我正在使用的项目中遇到新的链接器错误:
1>MSVCMRTD.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std.basic_string<char,std::char_traits<char>,std::allocator<char> >): (0x0200004e).
1>MSVCMRTD.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std.basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >): (0x02000075).
1>MSVCMRTD.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std._String_iterator<char,std::char_traits<char>,std::allocator<char> >): (0x02000091).
1>MSVCMRTD.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std._String_const_iterator<char,std::char_traits<char>,std::allocator<char> >): (0x02000092).
1>MSVCMRTD.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std._String_val<char,std::allocator<char> >): (0x02000097).
1>MSVCMRTD.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std._String_val<wchar_t,std::allocator<wchar_t> >): (0x02000099).
我们在 Windows 7 中使用 Visual Studio 2010。
这个项目用来编译。它是围绕一些非托管代码的 C++/CLI DLL 包装器,因此包括公共语言运行时支持。 改变 的是我们链接到的外部静态库被“更新”了。当我们尝试编译链接到它的项目时,我们现在遇到了这个错误。
微软对此问题的“帮助”是“在目标文件上运行 ildasm –tokens 以查找哪些类型具有 error_message 中列出的令牌,并查找差异”。然后我检查了 这个页面,发现 /tokens
选项只对 .exe 和 .dll 文件有效……但这是一个链接器错误,所以我的 .dll 文件还没有生成!
我试过运行 ildasm -tokens AssemblyInfo.obj
之类的东西,但唯一发生的事情是打开一个窗口并显示这个非常有用的错误消息:
感谢微软!
我不确定如何继续解决此问题。 Release 构建工作正常——只有 Debug 搞砸了。所以在混合的某个地方,我猜 std::string
类型的大小不同或其他什么……
有任何想法吗?
原文由 aardvarkk 发布,翻译遵循 CC BY-SA 4.0 许可协议
好的,所以我解决了!还有 另一个 SO 问题 实际上是一个很大的帮助。它最终链接到 这篇文章,其中有更多关于这个问题的细节。基本上这是在托管和非托管代码中编译标准库字符串的一些问题。解决方案是仅在需要它的文件上启用 CLR。详细地说,这就是我所做的:
/clr
开关.cpp
文件,在/clr
C/C++ -> General -> Common Language RunTime Support
。Program Database /Zi
Program Database for Edit and Continue /ZI
。这消除了警告,因为我认为/clr
支持似乎禁用了增量链接,然后我的本机代码抛出警告,因为它试图使用编辑并继续。ExtensionAttribute
警告,我通过在我的/clr
启用的文件中添加以下开关来修复它:/clr:nostdlib /AI"%ProgramFiles%\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0"
/clr
启用的文件上的一堆调试选项。 Specifically, underC/C++ -> Code Generation
, I setEnable Minimal Rebuild
toNo (/RM-)
, andBasic Runtime Checks
toDefault
.这也摆脱了一堆警告。Enable C++ Exceptions
设置为No
在clr
启用的文件上。希望这可以帮助!