我已将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' (
std::ifstream fin(filename, std::ifstream::in);
493) 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' (
std::ifstream fin(filename, std::ifstream::in);
4DD) 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
如何解决该问题或如何更改该代码行而不必更改其余代码?
最佳答案 从本质上讲,您正在编译包含< fstream>的托管代码.头.这意味着来自< fstream>的所有声明编译好像它们也被管理.然而,CRT DLL包含< fstream>的非托管版本.
在链接时,当导入lib MSVCMRTD.lib包含非托管std :: _ Container_base类时会检测到此情况,但是.obj文件需要托管std :: _ Container_base.
(_C告诉我们它是一个实现助手类).