LNK2022 元数据操作:重复类型中的布局信息不一致 [英] LNK2022 metadata operation: Inconsistent layout information in duplicated types

查看:11
本文介绍了LNK2022 元数据操作:重复类型中的布局信息不一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理的项目中遇到新的链接器错误:

1>MSVCMRTD.lib(locale0_implib.obj) : 错误 LNK2022: 元数据操作失败 (8013118D) : 重复类型中的布局信息不一致 (std.basic_string,std::allocator<char>>): (0x0200004e).1>MSVCMRTD.lib(locale0_implib.obj):错误 LNK2022:元数据操作失败 (8013118D):重复类型中的布局信息不一致 (std.basic_string,std::allocator>;): (0x02000075).1>MSVCMRTD.lib(locale0_implib.obj):错误 LNK2022:元数据操作失败 (8013118D):重复类型中的布局信息不一致 (std._String_iterator<char,std::char_traits<char>,std::allocator<char>>): (0x02000091).1>MSVCMRTD.lib(locale0_implib.obj):错误 LNK2022:元数据操作失败 (8013118D):重复类型中的布局信息不一致 (std._String_const_iterator,std::allocator;): (0x02000092).1>MSVCMRTD.lib(locale0_implib.obj):错误 LNK2022:元数据操作失败 (8013118D):重复类型中的布局信息不一致 (std._String_val>):(0x02000097).1>MSVCMRTD.lib(locale0_implib.obj):错误 LNK2022:元数据操作失败 (8013118D):重复类型中的布局信息不一致 (std._String_val<wchar_t,std::allocator<wchar_t>>):(0x02000099).

我们在 Windows 7 中使用 Visual Studio 2010.

这个项目用来编译.它是围绕一些非托管代码的 C++/CLI DLL 包装器,因此包括公共语言运行时支持.改变的是我们链接到的外部静态库已更新".当我们尝试编译链接到它的项目时,我们现在遇到了这个错误.

Microsoft 对此问题的帮助"是在目标文件上运行 ildasm –tokens 以查找哪些类型具有 error_message 中列出的令牌,并查找差异".然后我检查了 这实际上是一个很大的帮助.它最终链接到 这篇文章,里面有关于这个问题的更多细节.基本上这是在托管和非托管代码中编译标准库字符串的一些问题.解决方案是仅在需要它的文件上启用 CLR.详细来说,这是我所做的:

  1. 移除了应用于整个项目
  2. /clr开关
  3. 选中实际需要CLR的两个.cpp文件,在C/C++->下手动选中/clr;一般->公共语言运行时支持.
  4. 将整个项目从Program Database for Edit and Continue/ZI切换到Program Database/Zi.这消除了警告,因为我认为 /clr 支持似乎禁用了增量链接,然后我的本机代码抛出警告,因为它试图使用编辑并继续.
  5. 然后我收到了一些 ExtensionAttribute 警告,我通过将以下开关添加到启用了 /clr 的文件中来修复了这些警告:/clr:nostdlib/AI"%ProgramFiles%Reference AssembliesMicrosoftFramework.NETFrameworkv4.0"
  6. 在调试版本中,我不得不在启用 /clr 的文件上禁用一堆调试选项.具体来说,在 C/C++ ->代码生成,我将 Enable Minimal Rebuild 设置为 No (/RM-),并将 Basic Runtime Checks 设置为 Default.这也消除了一堆警告.
  7. 在调试和发布版本中,在启用 clr 的文件上将 Enable C++ Exceptions 设置为 No.

希望这会有所帮助!

I'm having a new-to-me linker error in a project I'm working with:

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).

We're using Visual Studio 2010 in Windows 7.

This project used to compile. It's a C++/CLI DLL wrapper around some unmanaged code, and thus includes Common Language Runtime Support. The thing that has changed is that an external static library that we linked to was "updated". We're now getting this error when we try to compile the project that links to it.

Microsoft's "help" for this issue is to "run ildasm –tokens on the object files to find which types have the tokens listed in error_message, and look for differences". Then I checked this page and noticed that the /tokens option is only valid for .exe and .dll files... but this is a linker error, so my .dll file isn't made yet!

I've tried running things like ildasm -tokens AssemblyInfo.obj, but the only thing that happens is that a window opens up with this incredibly helpful error message:

Thanks Microsoft!

I'm not really sure how to continue troubleshooting this issue. A Release build works properly -- it's only the Debug that's messed up. So somewhere in the mix I guess the std::string type is of a different size or something...

Any ideas?

解决方案

Alright, so I solved it! There was another SO question that was actually a big help. It ended up linking to this article, which had a bit more detail about the problem. Basically it's some issue with the standard library strings getting compiled in both managed and unmanaged code. The solution was to only enable the CLR on files which required it. In detail, here's what I did:

  1. Removed the /clr switch which applied to the whole project
  2. Selected the two .cpp files that actually required the CLR, and manually selected /clr under C/C++ -> General -> Common Language RunTime Support.
  3. Switched the whole project to Program Database /Zi from Program Database for Edit and Continue /ZI. This got rid of warnings, because I think /clr support appeared to disable incremental linking, and then my native code was throwing warnings because it was trying to use Edit and Continue.
  4. I then got some ExtensionAttribute warnings, which I fixed by adding the following switches to my /clr-enabled files: /clr:nostdlib /AI"%ProgramFiles%Reference AssembliesMicrosoftFramework.NETFrameworkv4.0"
  5. In Debug builds, I had to disable a bunch of debug options on the /clr-enabled files. Specifically, under C/C++ -> Code Generation, I set Enable Minimal Rebuild to No (/RM-), and Basic Runtime Checks to Default. This got rid of a bunch of warnings also.
  6. In Debug and Release builds, set Enable C++ Exceptions to No on the clr-enabled files.

Hope this helps!

这篇关于LNK2022 元数据操作:重复类型中的布局信息不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆