1

I have a weird linker error that I can't seem to straighten out. This project is actually a Windows port of our system on Linux, so we know everything is working before the port to Windows.

I'm compiling FTGL (OpenGL font lib) as a static library using VS2013 (compiles fine) and I'm using that static lib in a DLL. However, I get linker errors saying it cannot find symbols that are, from what I can tell, there:

Error   1   error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall FTPoint::FTPoint(void)" (__imp_??0FTPoint@@QAE@XZ) referenced in function "public: virtual void __thiscall FPSCounter::draw(class Projector const *)" (?draw@FPSCounter@@UAEXPBVProjector@@@Z)  E:\Desktop\libWCLVS\fpsCounter\fpsCounter.obj   fpsCounter

Error   2   error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall FTPoint::FTPoint(double,double,double)" (__imp_??0FTPoint@@QAE@NNN@Z) referenced in function "public: virtual void __thiscall FPSCounter::draw(class Projector const *)" (?draw@FPSCounter@@UAEXPBVProjector@@@Z)   E:\Desktop\libWCLVS\fpsCounter\fpsCounter.obj   fpsCounter

"dumpbin.exe /symbols" on the FTGL static lib shows the following (amongst the rest):

1E5 00000000 SECT10 notype ()    External     | ??0FTPoint@@QAE@XZ (public: __thiscall FTPoint::FTPoint(void))

1E6 00000000 SECTE  notype ()    External     | ??0FTPoint@@QAE@NNN@Z (public: __thiscall FTPoint::FTPoint(double,double,double))

Now so far this has been compiling the static library and my DLL in separate VS solutions (both debug builds). If I import the existing static lib VS project into my DLL solution and create a reference to it via the project's Common Properties -> References, the DLL compiles, links and executes fine (also as debug build). This seems odd to me, as since I'm using the same project in a different solution, it will be compiling the same and thus I should have the same undefined symbols.

Obviously VS is doing something different in linking them when in same solution versus exporting the lib and then linking against it. Does anyone know why I would be getting this kind of behaviour and what I could do try and resolve it?

valiano
  • 16,433
  • 7
  • 64
  • 79
walshy002000
  • 99
  • 1
  • 10
  • I know that when I setup projects that reference a static lib, I reference the DLL from the release folder and create a pre-build step that builds it. As far as I know you have to link to a DLL, not just reference the project. Or at least thats also never worked for me either. – BoldAsLove Feb 04 '15 at 05:03
  • Link the static lib directly: Configuration Properties -> Linker -> Input -> Additional Dependencies – rpress Feb 04 '15 at 10:39
  • Sorry should have clarified, I'm already linking to it in Configuration Properties -> Linker -> Input -> Additional Dependencies, as I've got a bunch of other libs also linked in. As for the DLL, I am building that and it is available for loading, but that's only loaded at runtime, not when linking. – walshy002000 Feb 04 '15 at 22:31
  • The symbols not found by the linker are marked `__declspec(dllimport)` so you're either building the static lib as a DLL from the compiler's view or you include the headers of the FTGL in your DLL code so that the compilers sees the '__declspec(dllimport)' instead of normal symbol. After shortly checking the sources of FTGL: you need to define FTGL_LIBRARY_STATIC. – rpress Feb 05 '15 at 00:15

1 Answers1

1

Ah! Thanks rpress, I had looked at FTGL_LIBRARY_STATIC and checked it was defined in the FTGL project, but it wasn't defined in my application that was including the FTGL header and thus my program was going to do the dllimport. Just added the FTGL_LIBRARY_STATIC to my application's project and it all works. Thanks!

walshy002000
  • 99
  • 1
  • 10