0

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?

Jessica Chambers
  • 1,246
  • 5
  • 28
  • 56
  • It's impossible to answer this question (or even to confirm whether your theory is right) unless you post the code that declares the missing functions. How do you declare `UserTracking` in your code? Presumably you include a header file, then look inside that header file, find the declaration of `UserTracking` and post it here. – john Aug 07 '20 at 10:53
  • 1
    Of course there are many other reasons that you could be experiencing these errors. The reason you have given is not impossible, but it would be unusual. – john Aug 07 '20 at 10:54
  • @john Hi, thanks - I added the function definition of UserTracking as an example – Jessica Chambers Aug 07 '20 at 11:01
  • The code you posted is the definition. I wanted to see the declaration. As I said this is likely to be in a header file. – john Aug 07 '20 at 11:05
  • @john I realized my mistake - I fixed it up with another function that is clearer – Jessica Chambers Aug 07 '20 at 11:08
  • 1
    So since we're now talking about a class method any macro use will be before the class definition in the header file e.g. `class SOMETHING EACServer ...`, its the SOMETHING part I'm interested in. – john Aug 07 '20 at 11:14
  • @john I added the definition to the post, but there isn't a SOMETHING ... – Jessica Chambers Aug 07 '20 at 11:18
  • 1
    Well it's hard to be sure without seeing all the code but it seems that your code is missing the usual macros to import/export a function from a DLL. Normally there is a macro which can be defined two ways, one way to export the function (that's what you use when compiling the DLL) and another way to import the function (that's what the code that is using the DLL has). See here for more details https://learn.microsoft.com/en-us/cpp/cpp/dllexport-dllimport?view=vs-2019 – john Aug 07 '20 at 11:58
  • @john thank you so much for the starting point, I had no idea where to begin – Jessica Chambers Aug 07 '20 at 12:00
  • https://stackoverflow.com/questions/30581837/linker-error-when-calling-a-c-function-from-c-code-in-different-vs2010-project/30583411#30583411, https://stackoverflow.com/questions/32156336/how-to-include-openssl-in-visual-studio, https://stackoverflow.com/questions/34748913/lnk2005-error-in-clr-windows-form. – CristiFati Aug 07 '20 at 16:37

1 Answers1

1

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.

Jessica Chambers
  • 1,246
  • 5
  • 28
  • 56