静态库中未定义的符号,但在同一VS解决方案中存在

时间:2015-02-04 04:56:58

标签: c++ visual-studio linker lnk2019 ftgl

我有一个奇怪的链接器错误,我似乎无法理顺。这个项目实际上是Linux上我们系统的Windows端口,因此我们知道在端口到Windows之前一切正常。

我使用VS2013编译FTGL(OpenGL字体库)作为静态库(编译正常),并且我在DLL中使用该静态库。但是,我收到链接器错误,说它无法找到符号,从我所知道的那里:

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))

现在到目前为止,这已经在单独的VS解决方案(两个调试版本)中编译静态库和我的DLL。如果我将现有的静态lib VS项目导入我的DLL解决方案并通过项目Common Properties -> References创建对它的引用,则DLL编译,链接并执行正常(也作为调试版本)。这对我来说似乎很奇怪,因为我在不同的解决方案中使用相同的项目,它将编译相同的,因此我应该有相同的未定义符号。

显然,当在同一解决方案中导出lib然后链接它时,VS正在做一些不同的连接。有谁知道为什么我会得到这种行为以及我能做些什么来尝试并解决它?

1 个答案:

答案 0 :(得分:0)

啊!谢谢rpress,我看过FTGL_LIBRARY_STATIC并检查它是在FTGL项目中定义的,但它没有在我的应用程序中定义,包括FTGL头,因此我的程序将进行dllimport。刚刚将FTGL_LIBRARY_STATIC添加到我的应用程序的项目中,一切正常。谢谢!