自定义属性不一致?
我已将 C++ 库转换为托管库,并在此代码行上收到以下错误:
std::ifstream fin(filename, std::ifstream::in);
错误:
Error 30 error LNK2022: metadata operation failed (80131195) : Custom attributes are not consistent: (0x0c0003b5). C:\Users\Freeman\Documents\Visual Studio 2010\Projects\testsharp1\cpp1\MSVCMRTD.lib(locale0_implib.obj)
Error 32 error LNK2034: metadata inconsistent with COFF symbol table: symbol '??0_Container_base12@std@@$$FQAE@XZ' (06000493) has inconsistent metadata with (0A000075) in MSVCMRTD.lib(locale0_implib.obj) C:\Users\Freeman\Documents\Visual Studio 2010\Projects\testsharp1\cpp1\LINK
Error 59 error LNK2034: metadata inconsistent with COFF symbol table: symbol '?memcpy@@$$J0YAPAXPAXPBXI@Z' (060004DD) has inconsistent metadata with (0A0003E3) in MSVCMRTD.lib(locale0_implib.obj) C:\Users\Freeman\Documents\Visual Studio 2010\Projects\testsharp1\cpp1\LINK
Error 60 error LNK1255: link failed because of metadata errors C:\Users\Freeman\Documents\Visual Studio 2010\Projects\testsharp1\cpp1\LINK
如何修复该问题或如何更改该代码行而无需更改其余代码?
i have converted a C++ library to managed and get the following error on this code line:
std::ifstream fin(filename, std::ifstream::in);
Errors:
Error 30 error LNK2022: metadata operation failed (80131195) : Custom attributes are not consistent: (0x0c0003b5). C:\Users\Freeman\Documents\Visual Studio 2010\Projects\testsharp1\cpp1\MSVCMRTD.lib(locale0_implib.obj)
Error 32 error LNK2034: metadata inconsistent with COFF symbol table: symbol '??0_Container_base12@std@@$FQAE@XZ' (06000493) has inconsistent metadata with (0A000075) in MSVCMRTD.lib(locale0_implib.obj) C:\Users\Freeman\Documents\Visual Studio 2010\Projects\testsharp1\cpp1\LINK
Error 59 error LNK2034: metadata inconsistent with COFF symbol table: symbol '?memcpy@@$J0YAPAXPAXPBXI@Z' (060004DD) has inconsistent metadata with (0A0003E3) in MSVCMRTD.lib(locale0_implib.obj) C:\Users\Freeman\Documents\Visual Studio 2010\Projects\testsharp1\cpp1\LINK
Error 60 error LNK1255: link failed because of metadata errors C:\Users\Freeman\Documents\Visual Studio 2010\Projects\testsharp1\cpp1\LINK
How to fix that or how to change that code line without having to change the rest of the code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
本质上,您正在编译包含
标头的托管代码。这意味着来自
的所有声明也将被编译,就好像它们是被管理的一样。然而,CRT DLL 包含
的非托管版本。在链接时,当导入库
MSVCMRTD.lib
包含非托管std::_Container_base
类,但您的 .obj 文件需要托管std 时,会检测到这一点: :_Container_base
。(
_C
告诉我们它是一个实现帮助器类)。Essentially, you're compiling your managed code which includes the
<fstream>
header. That means that all declarations from<fstream>
are compiled as if they're managed, too. Yet the CRT DLL contains unmanaged versions of<fstream>
.At link time, this is detected when the import lib
MSVCMRTD.lib
contains the unmanagedstd::_Container_base
class, but your .obj files need a managedstd::_Container_base
.(The
_C
tells us it's an implementation helper class).我知道这个问题已经很老了,但是经过 1 周的努力解决这个问题后,我决定将我找到的解决方案发布给任何可能遇到类似错误的人。
就我而言,我有两个项目,一个不受所有地方的 std 托管(列表、向量和队列,这是一个也应该在 Linux 上工作的项目,所以我不能使用 .net 集合),以及纯标准 C++ 代码,在第二个项目我创建了一个托管项目来包装这些类以在.net项目中使用,我使用的是Visual Studio 2010,尝试使用框架2.0,不幸的是VS 2010对VC++没有很好的支持,我尝试了一切强制它使用2.0,但没有成功,每次编译时我都会收到同样令人讨厌的消息“不一致的废话”。
我安装了 VS 2008,将项目移植到 2008,瞧!一切都在 10 分钟内完成,我花了 1 周的时间试图在 VS 2010 和 2008 中解决这个问题。
我希望这可以节省大量时间来解决在 VS 2010 上似乎无法解决的问题。
I know this question is old, but after 1 week struggling to solve this I feel committed to post the solution I found to whoever could be fighting with a similar error.
In my case I'd two projects, one unmanaged with std's all over the place (list, vectors and queues, this is a project which should work on linux too so I cannot use .net collections), and pure standard C++ code, on the second project I create a managed project to wrap this classes to be used in .net projects, I was using Visual Studio 2010, trying to use framework 2.0, unfortunatelly VS 2010 does not have a nice support to VC++, and I tried everything to force it to use 2.0, without success, everytime I compiled I got the same annoying message "Inconsistent blah".
I installed VS 2008, ported the projects to 2008 and voila! everything worked in 10 mins, I spend 1 week trying to solve this in VS 2010 and 2008 did the trick.
I hope this might save a lot of hours trying to solve something that appears to be unsolvable on VS 2010.