I have a Visual Studio C++ project containing main program and a DLL module. The DLL has a class with the following definition:
// .h
#ifdef _USRDLL
#define DLLAPI __declspec(dllexport)
#else
#define DLLAPI __declspec(dllimport)
#endif
class DLLAPI EClass
{
public:
static int value;
static int get_value();
};
// .cpp
int EClass::value = 1;
int EClass::get_value()
{
return value;
}
The DLL project is compiled successfully, both symbols (value and get_value) are observable by Dependency Walker.
In the main program, I can call the static function get_value
int v = EClass::get_value(); // Ok, v = 1
but when I try to access the field value
directly
int v = EClass::value; // Error
I get an error
LNK2001 unresolved external symbol "public: static int EClass::value" (?value@EClass@@2HA)
It is possible to avoid using accessors for static fields?