我有一个VS2010解决方案,其中包含(以及其他)以下项目:
伪代码(非常简化):
using namespace std;
bool Native::CalcSomething(double* result, string& errorMsg);
伪代码(非常简化)
bool Wrapper::WrappedCalcSomething([System::Runtime::InteropServices::OutAttribute] double[] result,[System::Runtime::InteropServices::OutAttribute] System::String^ errorMsg)
{
Native* ntv = new Native();
std:string error;
pin_ptr<double> resultPtr = &result[0];
bool success = ntv->CalcSomething(resultPtr, error);
errorMsg = gcnew System::String(error.c_str());
return success;
}
这在VS2008(x64)中完美编译和链接,但在迁移到VS2010后(由于各种原因),链接器会出现以下错误:
2> Generating Code...
2>MSVCMRTD.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std.logic_error): (0x02000049).
2>MSVCMRTD.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std.domain_error): (0x0200004a).
2>MSVCMRTD.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std.invalid_argument): (0x0200004b).
2>MSVCMRTD.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std.length_error): (0x0200004c).
2>MSVCMRTD.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std.out_of_range): (0x0200004d).
2>MSVCMRTD.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std.runtime_error): (0x0200004e).
2>MSVCMRTD.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std.overflow_error): (0x02000050).
2>MSVCMRTD.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std.underflow_error): (0x02000051).
2>MSVCMRTD.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std.range_error): (0x02000052).
2>MSVCMRTD.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std._Locinfo): (0x02000054).
2>MSVCMRTD.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (_Locimp): (0x02000059).
2>MSVCMRTD.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (failure): (0x02000068).
2>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).
2>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).
2>MSVCMRTD.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (lconv): (0x020000ce).
2>LINK : fatal error LNK1255: link failed because of metadata errors
我已经阅读了几乎所有关于这个问题的帖子,并尝试过:
我能想到的唯一“解决方案”是将Native.DLL中的方法更改为不使用std:string作为参数(例如,使用char *)。但是,为了避免在任何C ++ / CLI包装器中使用STL,这似乎不是一个解决方案。 必须是更好的方式!
注意:我知道有关如何“调试”这些问题的文章(link),但除非我弄错了,我想我知道问题的根源是std:string。< / p>
答案 0 :(得分:4)
我明白了。
我在其中一个CMake文件中进行了语法更改,我认为这些文件在功能上与之前发生的相同(基本上我使用的是CMake便利变量)。但是,这当然会产生意想不到的后果,因此产生的项目文件也不尽相同。
具体来说,Wrapper.DLL项目现在链接到它根本不需要链接的第三方ITK库(只有Native.DLL需要这些)。
在更换CMake并正确生成项目后,可怕的LNK2022消失了。我只能责怪所有浪费的时间......