C++ msbuild 缺少符号链接错误,但 Visual Studio 没有(调试)
我有一个本机 C++ 解决方案,其中包含一个库和一个使用该库的控制台应用程序(工具)。该库有很多工具未使用的外部符号(该库稍后也会在提供这些符号的主程序中使用)
在 Visual Studio 中一切构建良好(2017/2019/2022)
使用 msbuild 构建解决方案时发布版本很好,但调试版本失败,缺少近 200 个符号。这很重要,因为这就是自动化构建事物的方式。
msbuild MyLibrary.sln /p:Configuration=debug /p:Platform=Win32
示例链接错误:
mylibrary.lib(scope.obj) : error LNK2019: unresolved external symbol "bool __cdecl Cnxres(char const *,int &)" (?Cnxres@@YA_NPBDAAH@Z) referenced in function "public: bool __thiscall MyScope::getBooleanExpressionResult(void)" (?getBooleanExpressionResult@MyScope@@QAE_NXZ)
这将库作为静态消耗,即 mylibrary.lib 这些缺失的符号均未被该工具使用,并且位于库外部。
但是,如果我将工具更改为不链接库,而是重新编译相关源代码(3 个 cxx 文件),从而与 obj 链接,则 msbuild 会成功。
我正在努力解释这种行为,实际上我更愿意使用该库,因为这将允许我分离构建过程
I have a native C++ solution with a library and a console application (tool) that consumes the library. The library has quite a few external symbols that are not used by the tool (the library is also consumed later in the main program which supplies these symbols)
Everything builds fine in Visual Studio (2017/2019/2022)
When building the solution with msbuild the release build is fine but the debug build fails with nearly 200 missing symbols. This is important as this is how the automation builds things.
msbuild MyLibrary.sln /p:Configuration=debug /p:Platform=Win32
example link error:
mylibrary.lib(scope.obj) : error LNK2019: unresolved external symbol "bool __cdecl Cnxres(char const *,int &)" (?Cnxres@@YA_NPBDAAH@Z) referenced in function "public: bool __thiscall MyScope::getBooleanExpressionResult(void)" (?getBooleanExpressionResult@MyScope@@QAE_NXZ)
This is consuming the library as a static i.e. mylibrary.lib
These missing symbols are all unused by the tool and are external to the library.
If however, I change the tool to not link against the library but to recompile the relevant source code (3 cxx files) and thus link with the objs then msbuild succeeds.
I am struggling to explain the behaviour and really I would prefer to consume the library as that will allow me to separate the build process
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论