我正在将 native C++ Visual Studio 2010 项目转换为 Visual Studio 2015,在修复了一堆其他问题后,我终于进入了链接阶段,该阶段失败并出现以下错误
ucrtd.lib(ucrtbased.dll) : error LNK2005: __crt_debugger_hook already defined in msvcrtd.lib(utility_desktop.obj)
考虑到这可能是 C 运行时库不匹配,我返回并使用 VS2015 和/MDd 开关重新编译了所有依赖项以控制使用哪个运行时。那没有解决任何问题。
根据 dumpbin,符号 __crt_debugger_hook
存在于两个库中,但它只出现在 msvcrtd.lib 的符号表中。
我的解决方案中还有其他可执行文件与 ucrtd.lib 和 msvcrtd.lib 链接,但不会遇到此问题。遇到链接失败的可执行文件也与 MFC 和 BCG 链接,但我不明白这可能是什么原因。
是否有人对可能导致此问题的原因有任何其他想法?
最佳答案
事实证明,该错误不在 Microsoft 的库中。相反,它位于 Crypto++ ( https://www.cryptopp.com/) 库中。他们转发声明 _crt_debugger_hook
的方式与 Microsoft 在将 c-runtime 拆分为 ucrtd.lib 和 msvrtd.lib 时所做的更改不兼容。违规行是第 21 行的 fipstest.cpp:
extern "C" {_CRTIMP void __cdecl _CRT_DEBUGGER_HOOK(int);}
需要删除 _CRTIMP
以便您拥有
extern "C" {void __cdecl _CRT_DEBUGGER_HOOK(int); }
我已经向 Crypto++ 人员发起了一个拉取请求来解决这个问题 ( https://github.com/weidai11/cryptopp/pull/151 )。
关于c++ - ucrtd.lib 和 msvcrtd.lib 中都定义了 __crt_debugger_hook?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35734683/