Static link error

closed account (ozqpfSEw)
Hi everyone,
Since i moved to vs2010 i'm having this annoying link error 2001.
I declared some static const class members in my class and usually this error comes when you forget to declare the static fields in the source file. But in my case i actually did declare them (as you can see above).

I get the error when i try to use those static members, like VxColor::VxRed.
Should i use something like __declspec() in the declaration or the definition? Or did i mis something else?


Header file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class __declspec(dllexport) VxColor
{
    public:
        //! Constructor
        inline VxColor(float _R, float _G, float _B, float _A = 255);

    public:
        float r, g, b, a;

        const static VxColor VxBlack;       /**< Black color */
        const static VxColor VxRed;         /**< Red color */
        const static VxColor VxGreen;       /**< Green color */
        const static VxColor VxBlue;        /**< Blue color */
        const static VxColor VxYellow;      /**< Yellow color */
        const static VxColor VxCyan;        /**< Cyan color */

};



Source file:

1
2
3
4
5
6
7
8
#include "VxColor.hpp"

const VxColor VxColor::VxBlack(0,0,0);
const VxColor VxColor::VxRed(255,0,0);
const VxColor VxColor::VxGreen(0,255,0);
const VxColor VxColor::VxBlue(0,0,255);
const VxColor VxColor::VxYellow(255,255,0);
const VxColor VxColor::VxCyan(0,255,255);



Thank you for your time :)
I would try putting __declspec(dllexport) at the static member definitions and see if that fixes the issue.

1
2
3
__declspec(dllexport) const VxColor VxColor::VxBlack(0,0,0);
__declspec(dllexport) const VxColor VxColor::VxRed(255,0,0);
...
closed account (ozqpfSEw)
Nope, doesn't change a thing :/
Why does the class need to have that specification anyway? I think it is the root of the problem...
closed account (ozqpfSEw)
No specific reason, i just did it that way.
It works with other compilers such as gcc and vs2008, specification cannot be the only problem.
If it's for no reason, remove it. Does it work then?
closed account (ozqpfSEw)
my fault...
I have this defiened
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#if defined VX_WINDOWS

    #ifdef VX_DLL

        #ifdef VX_EXPORT

            #define VX_ENGINE __declspec(dllexport)

        #else

            #define VX_ENGINE __declspec(dllimport)

        #endif // VX_EXPORT
#endif 


VX_DLL was defined in the one project but not on the other project using the first one.

So the trick is to forget the use of __declspec() with your class and also not to forget to switch between dllexport and dllimport.
Topic archived. No new replies allowed.