链接对象中奇怪的未解决的外部错误

发布于 2024-09-07 18:38:13 字数 1087 浏览 2 评论 0原文

使用 Visual Studio 10 C++,我遇到奇怪的链接错误。由于某种原因,对全局对象的引用不会链接到该全局对象。它告诉我一个符号未定义,但当我让它查看 .cod 文件时,符号就在那里,一目了然。

错误:

FTShell.lib(ftcommodule.obj) : error LNK2001: unresolved external symbol
  "class CFTModuleShellBase * _pFTModule" (?_pFTModule@@3PAVCFTModuleShellBase@@A) 

但是主 cpp 文件的 .cod 文件显示了全局符号的声明和分配:

PUBLIC  ?_pFTModule@@3PAVCFTModuleShellBase@@A      ; _pFTModule

_DATA   SEGMENT
?_pFTModule@@3PAVCFTModuleShellBase@@A DD FLAT:?_Module@@3VCFTComModule@@A ; _pFTModule
    ORG $+4

那么为什么静态库的 _pFTModule 不与我的源文件中的全局符号匹配?

编辑:我从命令行运行了 msbuild:

Link:
C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\link.exe
/ERRORREPORT:QUEUE.... "C:\(path)\FTTrace.res"
"C:\(path)\FTTrace.obj"

我注意到最后只有一个 .obj 文件。项目中有两个.cpp 文件。 MSBUILD 确实构建了这两个文件。那么为什么它不将这两个文件传递给链接器呢? .vcxproj 文件不会以不同方式对待 .cpp 文件。为什么 MSBUILD 不在链接步骤中包含这两个文件?

<ItemGroup>
  <ClCompile Include="FTTrace.cpp" />
  <ClCompile Include="TraceImpl.cpp" />
</ItemGroup>

Using Visual Studio 10 C++, I'm having weird link error. For some reason references to a global object won't link to that global object. It is telling me a symbol is undefined yet when I have it view the .cod file the symbol is right there plain as day.

The error:

FTShell.lib(ftcommodule.obj) : error LNK2001: unresolved external symbol
  "class CFTModuleShellBase * _pFTModule" (?_pFTModule@@3PAVCFTModuleShellBase@@A) 

But the .cod file for the main cpp file shows both the declaration and allocation of the global symbol:

PUBLIC  ?_pFTModule@@3PAVCFTModuleShellBase@@A      ; _pFTModule

_DATA   SEGMENT
?_pFTModule@@3PAVCFTModuleShellBase@@A DD FLAT:?_Module@@3VCFTComModule@@A ; _pFTModule
    ORG $+4

So why wouldn't the static library's _pFTModule be matching the global symbol in my source file?

EDIT: I ran msbuild from the command line:

Link:
C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\link.exe
/ERRORREPORT:QUEUE.... "C:\(path)\FTTrace.res"
"C:\(path)\FTTrace.obj"

And I noticed at the end there is only one .obj file. There are two .cpp files in the project. And MSBUILD did build both file. So why didn't it pass both files on to the linker. The .vcxproj file doesn't treat the .cpp files differently. Why would MSBUILD not include both files on the link step?

<ItemGroup>
  <ClCompile Include="FTTrace.cpp" />
  <ClCompile Include="TraceImpl.cpp" />
</ItemGroup>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风筝在阴天搁浅。 2024-09-14 18:38:13

奇怪的是,该错误是将 ImpLib 属性设置为错误值的结果。属性表显示:$(OneOfMyPathVars)\%(Filename).lib。由于 %(Filename) 在链接阶段“C:\foo.lib”为空,因此不会创建 ImpLib。这导致项目中声明的函数无法解析外部。可能是链接器中的错误,但它是自己造成的。

Strangely enough, the error was the result of setting the ImpLib property to a bad value. The property sheet said: <ImpLib>$(OneOfMyPathVars)\%(Filename).lib</Implib>. Since %(Filename) was empty during the link stage "C:\foo.lib" causes no ImpLib to be created. And that caused the unresolved externals from functions declared in the project. Probably a bug in the linker but it was self-inflicted.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文