I have a DLL and lib file. I've included them in the root source directory and added the lib reference through Additional Dependencies. However, I get the following error:
1>main.obj : error LNK2001: unresolved external symbol "class game::c_State game::state" (?state@game@@3Vc_State@1@A)
fatal error LNK1120: 1 unresolved externals
which would be referencing this from "engine.h":
extern __declspec(dllexport) c_State state;
In "state.cpp" (from the DLL's source,) it is declared as
namespace game
{
c_State state;
//clipped for relevance
}
Could it be that I need to place the DLL somewhere specific? Does Windows know where to look? I found nowhere in the properties to specifically reference the DLL file, only the lib file.
Also, do I need a __declspec(dllexport) when declaring variables, or only functions?
Thanks in advance!
You have to apply __declspec(dllexport) to the definition, not the declaration. Also, the declaration needs __declspec(dllimport) in the other project. So in the .h file:
In the DLL source code file:
And in the DLL project use Project + Properties, C/C++, Proprocessor. Add FOO_EXPORTS to the preprocessor definitions.