Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
409 views
in Technique[技术] by (71.8m points)

c++ - LNK2022 Error When Using /clr

I'm having a problem linking a C++ project in VS2008 when using the /clr compile option. I am getting the following build errors:

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

I have no idea what PROPSHEETPAGEA and PROPSHEETPAGEW are referring to. I checked online to see Microsoft's description of the error but am at a loss as to what it means. http://support.microsoft.com/kb/324088

To resolve this problem, add unique identifiers when you use Managed Extensions for C++ so that you avoid using anonymous structures as global variables.

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in Microsoft Visual C++ .NET (2003).

Any ideas would be greatly appreciated.

EDIT

After doing a ildasm on Class1.obj I extracted two messages:

// 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)

I'm not sure what all this means, but it looks as if the second entry is identical to the first with the exception of the attributes being defined backwards.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I had this exact same problem today on one of my projects. I solved it by rearranging my header files. Problem was I had moved a header file to the top of the cpp file, before the file that was including windows.h. So, once I reverted the include order, and put windows.h back at the top of the cpp file, it fixed everything.

very wierd fix, but it worked for me.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...