0

I'm trying to build a solution in Visual C++ where I have a front-end project that references a DLL project that I created. In the DLL project I link to a static library (that I have not written) that has static objects and definitions. Everything builds fine but I have linking problems.

I have a couple of questions. First, I should only get unresolved symbols for objects that I reference in the front-end that are not exported, right? I want the DLL to be the only interface to the static library and do not directly reference any part of it in the front-end, and yet I get a number of unresolved symbols from this library. There symbols seem to be #included and at least some not directly linked by the DLL project. I suspect it has to do with the static declarations in the static lib but how can I deal with these?

Some of the unresolved symbol errors:

2>AnalysisVis.obj : error LNK2001: unresolved external symbol "public: __thiscall SharkException::SharkException(char const *,int,char const *)" (??0SharkException@@$$FQAE@PBDH0@Z)
2>AnalysisVis.obj : error LNK2001: unresolved external symbol "public: static class Bernoulli Rng::coinToss" (?coinToss@Rng@@2VBernoulli@@A)
2>AnalysisVis.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall ChromosomeT<bool>::operator<(class Chromosome const &)const " (??M?$ChromosomeT@_N@@$$FUBE_NABVChromosome@@@Z)
Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Nigel
  • 500
  • 5
  • 10
  • What's the point in using a DLL as an interface to a static library? Please explain! – TonyK Dec 06 '10 at 19:51
  • The DLL isn't just an interface to the static library, it has its own functionality but it makes use of the static library. – Nigel Dec 06 '10 at 21:19
  • possible duplicate of [static variable initialisation code never gets called](http://stackoverflow.com/questions/1897184/static-variable-initialisation-code-never-gets-called) – Martin York Dec 06 '10 at 22:13

1 Answers1

0

The exported symbols are mangled. If the static lib was compiled using a different compiler (or compiler version) than the one you are using, it is possible that the symbols your application is expecting to see were defined in the static lib using a different name mangling scheme. You can use the following command to get the name mangling used in the static lib and then compare it to the one in the error message:

>pushd <path_to_msvc_dir>\Microsoft Visual Studio X.0\VC\bin
>dumpbin /all [static_lib_path] > out.txt
>type out.txt | find /I "SharkException"
>type out.txt | find /I "coinToss"
>type out.txt | find /I "ChromosomeT"

BTW, does the DLL that uses the static lib compiles cleanly with the same compiler your application/solution does?

hillel
  • 2,343
  • 2
  • 18
  • 25
  • Yes, the DLL project is part of the same solution as the application and it compiles first cleanly. – Nigel Dec 06 '10 at 20:41
  • Also, I tried doing as you suggested and I find the following in the static lib: AD ??0SharkException@@QAE@PBDH0@Z, C9BCC4 ?coinToss@Rng@@2VBernoulli@@A, but I cannot find the ChromosomeT symbol there. Why are all three showing up then? And what can I do about this name mangling? – Nigel Dec 06 '10 at 20:47
  • The symbols show up in the lib because they were defined there. I would guess that your DLL's exported functions use these symbols but do not export them -- hence your problem. The dll interface may be using these symbols indirectly through DLL defined objects that rely on them -- this may be hard to track down. If your dll compiles cleanly then mangling is probably not an issue. Can you start removing stuff from your DLL interface in order to find out what's the offending object? Once you find it you can replace it with a pure DLL object and you should be Okay. – hillel Dec 06 '10 at 21:23
  • I now notice that the SharkException constructor defined in the lib is mangled in a different manner than the one your app uses to reference it. It may be a problem, but since you can't do much about the way symbols are mangled in your lib, you should go ahead with removing all lib symbols from your DLL interface. – hillel Dec 06 '10 at 21:29