lumberjack4
lumberjack4

Reputation: 2872

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.

Upvotes: 11

Views: 16788

Answers (9)

yash upadhyay
yash upadhyay

Reputation: 9

I too had this problem recently. It seems that before I made a my working form, I had made another form but deleted it. But somehow one of its .cpp file remained. Till the time I noticed it, I had this error. Once I removed the .cpp file of the deleted form, the prblem went away.

Upvotes: -1

Mikhael
Mikhael

Reputation: 1

In one of the dependent projects stdafx.h did not contain the following declaration:

#ifndef WINVER          // Allow use of features specific to Windows XP or later.
#define WINVER 0x0501   // Change this to the appropriate value to target other versions of Windows.
#endif

The result is different compilation file prsht.h in various projects.

In this file name is declared structure with _PROPSHEETPAGE.

VS 2008

Upvotes: 0

Dmitry Prihodko
Dmitry Prihodko

Reputation: 13

In my case one class declaration was dependent on some #define declared in a .h (testing #ifdef)which I forgot to include in one of the files using it. In result linker had 2 different descriptions of the class. In this situation check all files that include the related file with conditional declaration.

Upvotes: 0

user1603061
user1603061

Reputation: 51

I solved this issue simply by doing a "clean" on the overall solutuion. Seems that this just can happen if VS mixes things up.

Upvotes: 5

Chirag
Chirag

Reputation: 11

I was facing the same kind of problem, but later on I found that the class which was shown in the error was included twice. I had stored my main class header file into my project directory for backup purposes, and the original one was residing in the include folder of my project. It happened because I had included these two directory paths in my project's "Include Addition File Path" property.

Upvotes: 1

Choufler
Choufler

Reputation: 460

MSVCMRTD.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std.basic_string<char,std::char_traits<char>,std::allocator<char> >): (0x0200004f).
MSVCMRTD.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std.basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >): (0x02000075).

This error appears only in debug version, it's some kind of compiler bug. To fix it you can switch project setting

Configuration Properties\C/C++\Code Generation\Runtime Library

from

MultiThreaded Debug Dll (MDD)

to MultiThreaded Dll (MD) (for DLL). But then you'll have problems with debugging this code (e.g. with breakpoints)

Another way is to get rid of using stl classes in mixed code: completely in the project, or partly: divide your project into pure native (with Stl classes) and mixed parts, create different precompiled headers for them, switch off /clr for the whole project, and switch it on only for cpp's with mixed code.

Upvotes: 0

G.C.
G.C.

Reputation: 11

I had the same problem today, migrating my project from vs2008 to vs2010. While compiling a CLI project that links with other C++ libs, i got this link error on:

MSVCMRTD.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std.basic_string<char,std::char_traits<char>,std::allocator<char> >): (0x0200004f).
MSVCMRTD.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std.basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >): (0x02000075).

I tried ildasm as the documentation suggest, but could not find any type definitions that seems the same but having a different names.

moreover, I must say I do not completely understand this error. The fact that two errors appear means that there are two different problems with both types (char string and wchar string) or does it mean that there is one problem that these two types are causing. What is the meaning of the numbers in the end of the line (i did find two typedefs on the ildasm log with these numbers, though). There is nothing about that in the documentation.

BTW - same projects -same configuration compiles and links perfectly with vs2008.

Anyway, lost in the dark, I turned my other C++ lib, which link with the CLI project, into a CLI project as well (compiling it with /clr flag). relinking the main CLI project seems to solve the problem. Somehow adding the clr support or linking with clr resolve this types collision.

If someone have an educated explanation to this issue I would love to read it.

Upvotes: 1

C.J.
C.J.

Reputation: 16081

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.

Upvotes: 6

Mark B
Mark B

Reputation: 96241

It sounds like you're doing something like this:

struct
{
    int a;
    int b;
} global_struct;

which is anonymous. If you change it to:

struct UniqueNameHere
{
    int a;
    int b;
} global_struct;

that should fix up the errors.

Upvotes: 1

Related Questions