使用/clr
编译选项时,我在VS2008中连接C++项目时出现问题。我正在以下编译错误:使用/ clr时出现LNK2022错误
Class1.obj : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (_PROPSHEETPAGEA): (0x0200046f).
Class1.obj : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (_PROPSHEETPAGEW): (0x02000473).
Class2.obj : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (_PROPSHEETPAGEA): (0x0200046f).
Class2.obj : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (_PROPSHEETPAGEW): (0x02000473).
Class3.obj : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (_PROPSHEETPAGEA): (0x0200046e).
Class3.obj : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (_PROPSHEETPAGEW): (0x02000472).
Class4.obj : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (_PROPSHEETPAGEA): (0x0200046e).
Class4.obj : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (_PROPSHEETPAGEW): (0x02000472).
Class5.obj : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (_PROPSHEETPAGEA): (0x0200046e).
Class5.obj : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (_PROPSHEETPAGEW): (0x02000472).
Class6.obj : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (_PROPSHEETPAGEA): (0x0200046e).
Class6.obj : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (_PROPSHEETPAGEW): (0x02000472).
LINK : fatal error LNK1255: link failed because of metadata errors
我不知道什么PROPSHEETPAGEA
和PROPSHEETPAGEW
指的是。我在网上查了一下,看到微软对这个错误的描述,但是对于它的含义却不知所措。 http://support.microsoft.com/kb/324088
要解决此问题,当你使用控制对C++的扩展,使您避免使用匿名结构作为全局变量添加唯一标识符。
Microsoft已经确认这是本文开头列出的Microsoft产品中的错误。此错误已在Microsoft Visual C++ .NET(2003)中得到纠正。
任何想法将不胜感激。
编辑
上Class1.obj做了反汇编后,我提取两个消息:
// TypeDef #1134 (0200046f)
// -------------------------------------------------------
// TypDefName: _PROPSHEETPAGEA (0200046F)
// Flags : [NotPublic] [SequentialLayout] [Class] [Sealed] [AnsiClass] [BeforeFieldInit] (00100108)
// Extends : 0100000B [TypeRef] System.ValueType
// Layout : Packing:0, Size:56
// CustomAttribute #1 (0c0012a0)
// -------------------------------------------------------
// CustomAttribute Type: 0a000003
// CustomAttributeName: Microsoft.VisualC.MiscellaneousBitsAttribute :: instance void .ctor(int32)
// Length: 8
// Value : 01 00 41 00 00 00 00 00 > A <
// ctor args: (65)
//
// CustomAttribute #2 (0c0012a1)
// -------------------------------------------------------
// CustomAttribute Type: 0a000001
// CustomAttributeName: Microsoft.VisualC.DebugInfoInPDBAttribute :: instance void .ctor()
// Length: 4
// Value : 01 00 00 00 > <
// ctor args:()
//
// CustomAttribute #3 (0c0012a2)
// -------------------------------------------------------
// CustomAttribute Type: 0a000004
// CustomAttributeName: System.Runtime.CompilerServices.NativeCppClassAttribute :: instance void .ctor()
// Length: 4
// Value : 01 00 00 00 > <
// ctor args:()
// TypeDef #1138 (02000473)
// -------------------------------------------------------
// TypDefName: _PROPSHEETPAGEW (02000473)
// Flags : [NotPublic] [SequentialLayout] [Class] [Sealed] [AnsiClass] [BeforeFieldInit] (00100108)
// Extends : 0100000B [TypeRef] System.ValueType
// Layout : Packing:0, Size:56
// CustomAttribute #1 (0c0012b0)
// -------------------------------------------------------
// CustomAttribute Type: 0a000004
// CustomAttributeName: System.Runtime.CompilerServices.NativeCppClassAttribute :: instance void .ctor()
// Length: 4
// Value : 01 00 00 00 > <
// ctor args:()
//
// CustomAttribute #2 (0c0012b1)
// -------------------------------------------------------
// CustomAttribute Type: 0a000001
// CustomAttributeName: Microsoft.VisualC.DebugInfoInPDBAttribute :: instance void .ctor()
// Length: 4
// Value : 01 00 00 00 > <
// ctor args:()
//
// CustomAttribute #3 (0c0012b2)
// -------------------------------------------------------
// CustomAttribute Type: 0a000003
// CustomAttributeName: Microsoft.VisualC.MiscellaneousBitsAttribute :: instance void .ctor(int32)
// Length: 8
// Value : 01 00 41 00 00 00 00 00 > A <
// ctor args: (65)
我不知道这一切都说明,但它看起来好像第二项是与第一个相同,但属性被定义为向后的例外。
我修改了我的解决方案设置,将单个项目中的所有托管代码包含在内,而不是多个项目,并且错误消失。这将永远是一个谜... – lumberjack4 2010-10-12 16:10:53