1

I have a h- and a cpp-file with some calculations used in many of my projects.

Now I tried to put them in a separate dll, so the files should not be included in every project.

When linking I get a LNK2001 (unresolved symbol) error for a struct, however lib and dll are in the right place.

I use the

#ifdef TOOLS_EXPORTS
#define TOOLS_API __declspec(dllexport)
#else
#define TOOLS_API __declspec(dllimport)
#endif

macro, which works fine for a couple of methods.

The struct is defined like that

TOOLS_API typedef  struct  {
char Name[128];
}  uTSystem;

And in the files using this struct from the dll its also defined correctly(?)

extern uTSystem ABC;

The error message is:

error LNK2001: Nichtaufgeloestes externes Symbol "struct uTSystem ABC" (?ABC@@3UuTSystem@@A)

Any hints? Thank you

Simon
  • 1,616
  • 2
  • 17
  • 39
  • Do you get the LINK2001 when linking the DLL or the consuming application? It may also be helpful to include the exact error message. – harper Oct 21 '10 at 08:24
  • I get the error, when linking the dll – Simon Oct 21 '10 at 08:32
  • the error message is: error LNK2001: Nichtaufgeloestes externes Symbol "struct uTSystem ABC" (?ABC@@3UuTSystem@@A) – Simon Oct 21 '10 at 09:16
  • 1
    extern uTSystem ABC; in the class using this struct was wrong; uTSystem ABC; is sufficient – Simon Oct 21 '10 at 10:39

1 Answers1

1

Assuming you defined TOOLS_EXPORT when compile the DLL you will export the variable ABC. In your code you define it as extern uTSystem ABC; That's ok for the header file, that you share with the consuming DLL.

While the extern declares that there is a variable ABC you must define it in one of your .cpp file:

uTSystem ABC;

without the extern in front. Your file might look like this:

---- tools.h ----

#ifdef TOOLS_EXPORTS
#define TOOLS_API __declspec(dllexport)
#else
#define TOOLS_API __declspec(dllimport)
#endif

TOOLS_API typedef  struct  {
char Name[128];
}  uTSystem;

extern uTSystem ABC;

---- tools.cpp ----

#include tools.h

uTSystem ABC;
harper
  • 13,345
  • 8
  • 56
  • 105