LNK2022使用/ clr时出错 [英] LNK2022 Error When Using /clr

查看:902
本文介绍了LNK2022使用/ clr时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 / clr 编译选项时,我在连接VS2008中的C ++项目时遇到问题。我收到以下生成错误:

  Class1.obj:error LNK2022:元数据操作失败(8013118D):布局信息不一致重复类型(_PROPSHEETPAGEA):(0x0200046f)。 
Class1.obj:error LNK2022:元数据操作失败(8013118D):重复类型(_PROPSHEETPAGEW):(0x02000473)中布局信息不一致。
Class2.obj:error LNK2022:元数据操作失败(8013118D):重复类型(_PROPSHEETPAGEA):(0x0200046f)中布局信息不一致。
Class2.obj:error LNK2022:元数据操作失败(8013118D):重复类型(_PROPSHEETPAGEW):(0x02000473)中布局信息不一致。
Class3.obj:error LNK2022:元数据操作失败(8013118D):重复类型(_PROPSHEETPAGEA):(0x0200046e)中布局信息不一致。
Class3.obj:error LNK2022:元数据操作失败(8013118D):重复类型(_PROPSHEETPAGEW):(0x02000472)中布局信息不一致。
Class4.obj:error LNK2022:元数据操作失败(8013118D):重复类型(_PROPSHEETPAGEA):(0x0200046e)中布局信息不一致。
Class4.obj:error LNK2022:元数据操作失败(8013118D):重复类型(_PROPSHEETPAGEW):(0x02000472)中布局信息不一致。
Class5.obj:error LNK2022:元数据操作失败(8013118D):重复类型(_PROPSHEETPAGEA):(0x0200046e)中布局信息不一致。
Class5.obj:error LNK2022:元数据操作失败(8013118D):重复类型(_PROPSHEETPAGEW):(0x02000472)中布局信息不一致。
Class6.obj:error LNK2022:元数据操作失败(8013118D):重复类型(_PROPSHEETPAGEA):(0x0200046e)中布局信息不一致。
Class6.obj:error LNK2022:元数据操作失败(8013118D):重复类型(_PROPSHEETPAGEW):(0x02000472)中的布局信息不一致。
LINK:致命错误LNK1255:链接失败,因为元数据错误

PROPSHEETPAGEA PROPSHEETPAGEW 指的是。我在网上查看了微软的错误描述,但我的损失,这是什么意思。
http://support.microsoft.com/kb/324088


要解决此问题,请在使用C ++的托管扩展时添加唯一标识符,以避免使用匿名结构作为全局变量。



Microsoft已经确认这是本文开头列出的Microsoft产品中的错误。这个错误在Microsoft Visual C ++ .NET(2003)中得到纠正。


任何想法都将非常感激。
$ b

EDIT



在Class1.obj上做了一个ildasm后,我提取了两个消息:

  // TypeDef#1134(0200046f)
// ----------------- --------------------------------------
// TypDefName:_PROPSHEETPAGEA(0200046F)
//标记:[NotPublic] [SequentialLayout] [Class] [Sealed] [AnsiClass] [BeforeFieldInit](00100108)
//扩展:0100000B [TypeRef] System.ValueType
//布局:包装:0,大小:56
// CustomAttribute#1(0c0012a0)
// ----------------------- --------------------------------
// CustomAttribute类型:0a000003
// CustomAttributeName: Microsoft.VisualC.MiscellaneousBitsAttribute :: instance void.ctor(int32)
//长度:8
//值:01 00 41 00 00 00 00 00> A&
// ctor args:(65)
//
// CustomAttribute#2(0c0012a1)
// -------------- -----------------------------------------
// CustomAttribute类型: 0a000001
// CustomAttributeName:Microsoft.VisualC.DebugInfoInPDBAttribute :: instance void.ctor()
//长度:4
//值:01 00 00 00> <
// ctor args:()
//
// CustomAttribute#3(0c0012a2)
// --------------- ----------------------------------------
// CustomAttribute类型:0a000004
// CustomAttributeName:System.Runtime.CompilerServices.NativeCppClassAttribute :: instance void.ctor()
//长度:4
//值:01 00 00 00> <
// ctor args:()


// TypeDef#1138(02000473)
// ------------- ------------------------------------------
// TypDefName: _PROPSHEETPAGEW(02000473)
//标记:[NotPublic] [SequentialLayout] [Class] [Sealed] [AnsiClass] [BeforeFieldInit](00100108)
//扩展:0100000B [TypeRef] System.ValueType
// Layout:Packing:0,Size:56
// CustomAttribute#1(0c0012b0)
// ------------------- ------------------------------------
// CustomAttribute类型:0a000004
// CustomAttributeName:System.Runtime.CompilerServices.NativeCppClassAttribute :: instance void.ctor()
//长度:4
//值:01 00 00 00> <
// ctor args:()
//
// CustomAttribute#2(0c0012b1)
// --------------- ----------------------------------------
//自定义属性类型:0a000001
// CustomAttributeName:Microsoft.VisualC.DebugInfoInPDBAttribute :: instance void.ctor()
//长度:4
//值:01 00 00 00> <
// ctor args:()
//
// CustomAttribute#3(0c0012b2)
// --------------- ----------------------------------------
// CustomAttribute类型:0a000003
// CustomAttributeName:Microsoft.VisualC.MiscellaneousBitsAttribute :: instance void.ctor(int32)
//长度:8
//值:01 00 41 00 00 00 00 00> A&
// ctor args:(65)

我不知道这是什么意思,但它看起来好像第二个条目是相同的第一个,除了属性被向后定义。

解决方案

I今天在我的一个项目上有这个完全相同的问题。
我通过重新排列我的头文件解决了。问题是我把一个头文件移动到cpp文件的顶部,在包括windows.h的文件之前。
所以,一旦我恢复了include命令,并把windows.h回到cpp文件的顶部,它修复了一切。



非常精确的修正,但它对我有用。


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.

解决方案

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.

这篇关于LNK2022使用/ clr时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆