views:

105

answers:

1

Hi all!

I have a dynamic library (plugin) that uses another dynamic library (dependency). I use the dependency in two ways: a. by instantiating object from classes defined in the dependency b. by inheriting from classes defined in the dependency

When doing a., there are no linking errors. But when doing b., I have a linking error stating that I am missing some symbols (LNK2001). I looked in the .lib/.exp for the exact mangled name and did find the symbol that MSVC (2005) says is missing.

It might be important to say that I use Qt and that the missing symbols are symbols that are automatically generated in the moc files (staticMetaObject of the parent class). Also, it might be relevant to say that I get these errors in both debug and release, which means that they are not "optimized away" (I even tried /OPT:NOREF /OPT:NOICF, although its the default in debug builds and that the symbols are in the lib file...)

How can I have this linking error even though the symbols are in there? And most importantly, how can I fix these errors?

Thanks for any help!

+1  A: 

You might want to make sure the class is being declared with __declspec(dllexport) (when building) and __declspec(dllimport) (when linking against)?

See this link.

asveikau
Ok, now I feel silly. It was infact that the import macro was defined to nothing (not to __declspec(dllimport)).I just don't understand why it works in case a. but not in case b. In other words, why do you have to import classes you derive from but not those you use directly?
Geeho
my guess based on the link above is it's possible to still call some methods (for example if they're declared inline in the header or if they're virtual), but the second you need something the compiler/linker doesn't immediately have on hand, you get the error.
asveikau