简体   繁体   English

错误LNK2001:加载的静态库的未解析的外部符号

[英]error LNK2001: unresolved external symbol for static lib that is loaded

So I've been stuck on this for almost a month now. 所以我已经坚持了将近一个月了。 I have an MSVC++ project with a library in the proper directory, and Diagnostic build verbosity on. 我有一个MSVC ++项目,在正确的目录中有一个库,并在Diagnostic上显示详细信息。 The .LIB is statically compiled, and running: .LIB是静态编译的,并且正在运行:

dumpbin /headers GazeApiLib.lib

returns, among other things: 返回,其中包括:

     Code
     COMDAT; sym= "public: bool __cdecl gtl::GazeApi::connect(bool)" (?connect@GazeApi@gtl@@QEAA_N_N@Z)
     16 byte align
     Execute Read

But the verbose build fails with the following error: 但是详细的构建失败,并出现以下错误:

1>  C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\Tracker.exe /a /d C:\Windows\Microsoft.NET\Framework\v4.0.30319\FileTracker.dll /i "C:\Users\Snail\Documents\Visual Studio 2010\Projects\EyeTracker2\EyeTracker2\Release" /r "C:\USERS\SNAIL\DOCUMENTS\VISUAL STUDIO 2010\PROJECTS\EYETRACKER2\EYETRACKER2\GAZEAPILIB.LIB|C:\USERS\SNAIL\DOCUMENTS\VISUAL STUDIO 2010\PROJECTS\EYETRACKER2\EYETRACKER2\RELEASE\MAIN.OBJ" /b MSBuildConsole_CancelEventc512b4a37e0c4c399b5a3a0500474f44  /c "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\link.exe"  /ERRORREPORT:PROMPT /OUT:"C:\Users\Snail\Documents\Visual Studio 2010\Projects\EyeTracker2\Release\EyeTracker2.exe" /NOLOGO /LIBPATH:"C:\Users\Snail\Documents\Visual Studio 2010\Projects\EyeTracker2\EyeTracker2\libs" GazeApiLib.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /ManifestFile:"Release\EyeTracker2.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"C:\Users\Snail\Documents\Visual Studio 2010\Projects\EyeTracker2\Release\EyeTracker2.pdb" /OPT:REF /OPT:ICF /LTCG /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\Users\Snail\Documents\Visual Studio 2010\Projects\EyeTracker2\Release\EyeTracker2.lib" /MACHINE:X86 Release\main.obj
1>  GazeApiLib.lib (TaskId:27)
1>main.obj : error LNK2001: unresolved external symbol "public: bool __thiscall gtl::GazeApi::connect(bool)" (?connect@GazeApi@gtl@@QAE_N_N@Z)

Marking it as __cdecl manually in the header file gives this error instead: 在头文件中手动将其标记为__cdecl会出现以下错误:

1>main.obj : error LNK2001: unresolved external symbol "public: bool __cdecl gtl::GazeApi::connect(bool)" (?connect@GazeApi@gtl@@QAA_N_N@Z)

So on one hand it looks like it's successfully including the lib file but it can't seem to find the function even though the prototypes match exactly. 因此,一方面看起来它已成功包含lib文件,但即使原型完全匹配,也似乎找不到该函数。 What's going on? 这是怎么回事?

EDIT: Some more information, I ran undname and found that the unmangled name in the LIB file was: 编辑:一些更多的信息,我跑了undname,发现LIB文件中的未修改的名称是:

public: bool __cdecl gtl::GazeApi::connect(bool) __ptr64

which is slightly different than my code's signature, and which would explain why the mangled names don't match (?connect@GazeApi@gtl@@QAE_N_N@Z vs. ?connect@GazeApi@gtl@@QAA_N_N@Z) 这与我的代码签名略有不同,并且可以解释为什么名称不匹配(?connect @ GazeApi @ gtl @@ QAE_N_N @ Z与?connect @ GazeApi @ gtl @@ QAA_N_N @ Z

I'm pretty sure it's a wordsize difference between the 2 compilations. 我很确定这是两个编译之间的一个字眼差异。 Your lib uses 64-bit-sized pointers, while your project compiles to use 32-bit-sized. 您的lib使用64位大小的指针,而您的项目编译为使用32位大小的指针。 Note the E in the mangled name of the function in the lib, which means __ptr64 (?connect@GazeApi@gtl@@Q E AA_N_N@Z). 请注意,lib中函数的乱码名称中的E表示__ptr64(?connect @ GazeApi @ gtl @@ Q E AA_N_N @ Z)。 This gives, that the declaration of the function corresponding the one in the lib is 这给出了与lib中的那个相对应的函数的声明为

BOOL __cdecl gtl::GazeApi::connect(BOOL) __ptr64

I hope this helps 我希望这有帮助

EDIT: For similar problems in the future: http://demangler.com/ 编辑:对于将来类似的问题: http : //demangler.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM