tags:

views:

45

answers:

1

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?

A: 

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 unmanaged std::_Container_base class, but your .obj files need a managed std::_Container_base.

(The _C tells us it's an implementation helper class).

MSalters