Search code examples
c++visual-studiodlldeclspec

How to define macro which correctly sets the __declspec


Using Visual Studio 2017, I am trying to build my latest project which imports libraries, which in turn import methods and functions from .dll files.

When building my project, I get a list of errors like this:

error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl UserTracking(void *)" (__imp_?UserTracking@@YAXPEAX@Z)
error LNK2001: unresolved external symbol "public: bool __cdecl EACServer::Destroy(void)const " (?Destroy@EACServer@@QEBA_NXZ)
error LNK2001: unresolved external symbol "public: bool __cdecl EACServer::Initialize(void)const " (?Initialize@EACServer@@QEBA_NXZ)
...

All of the functions listed are from imported libraries.

As an example, the EACServer::Initialize method is defined as so in EACServer.h:

bool Initialize() const;

In the code I am compiling, this function is used as so (the appropriate header files are imported in the .h file ofc):

this->eacServer = EACServer();
this->eacServer.Initialize();

The class definition of EACServer is basic:

class EACServer : IRoot {
    ...
}

I have been told that these errors are thrown because I am missing the macro which correctly sets the __declspec.

How can I find/implement this macro?


Solution

  • Turns out that although I added the paths to my libraries in the linker additional library directories, I had neglected to add the .lib files in the linker additional dependencies.