VS 2005 SP on X64 LNK2022 problems

Giganews Newsgroups
Subject: VS 2005 SP on X64 LNK2022 problems
Posted by:  joepubb…@googlemail.com (joepubb…@googlemail.com)
Date: Wed, 20 Feb 2008

Hi,

I have been developing a mixed C# and C++ CLR project on XP 32 bit for
some time now without problems.  I have recently upgraded to Vista
x64.  Since then C++ CLR Class Library's that include windows.h do not
compile.  For the purpose of elimination I started a fresh C++ CLR
class library, included <windows.h> in it and simply compiled it.

// Test.h

#include <windows.h>

#pragma once

using namespace System;

namespace Test {

    public ref class Class1
    {
        // TODO: Add your methods for this class here.
    };
}

The linker throws the following errors

1>MSVCMRTD.lib(mstartup.obj) : error LNK2022: metadata operation
failed (8013118D) : Inconsistent layout information in duplicated
types (_GUID): (0x02000079).
1>MSVCMRTD.lib(mstartup.obj) : error LNK2022: metadata operation
failed (8013118D) : Inconsistent layout information in duplicated
types (_ldiv_t): (0x0200007a).
1>MSVCMRTD.lib(mstartup.obj) : error LNK2022: metadata operation
failed (8013118D) : Inconsistent layout information in duplicated
types (tagVARIANT): (0x02000081).
1>MSVCMRTD.lib(mstartup.obj) : error LNK2022: metadata operation
failed (8013118D) : Inconsistent layout information in duplicated
types (tagPROPVARIANT): (0x02000087).
1>MSVCMRTD.lib(msilexit.obj) : error LNK2022: metadata operation
failed (8013118D) : Inconsistent layout information in duplicated
types (_GUID): (0x0200001c).
1>MSVCMRTD.lib(msilexit.obj) : error LNK2022: metadata operation
failed (8013118D) : Inconsistent layout information in duplicated
types (_ldiv_t): (0x0200001d).
1>MSVCMRTD.lib(puremsilcode.obj) : error LNK2022: metadata operation
failed (8013118D) : Inconsistent layout information in duplicated
types (_GUID): (0x0200001c).
1>LINK : fatal error LNK1255: link failed because of metadata errors

Now I suspected this was something to do with me running on Vista
x64.  I changed the platform to x64 instead of Win32 and low and
behold, it compiles no problem.  Removal of the windows.h include also
allows the project to build but that limits my use of the Windows API
within the CLR project then.

I have included ildasm snippets below from the offending object files,
as you can see the two types don't match.

ildasm listing snippet from mstartup.obj

// TypeDef #120 (02000079)
// -------------------------------------------------------
//     TypDefName: _GUID  (02000079)
//     Flags    : [NotPublic] [SequentialLayout] [Class] [Sealed]
[AnsiClass]  (00000108)
//     Extends  : 01000009 [TypeRef] System.ValueType
//     Layout    : Packing:1, Size:16
//     CustomAttribute #1 (0c000157)
//     -------------------------------------------------------

ildasm listing snippet from Test.obj

// TypeDef #176 (020000b1)
// -------------------------------------------------------
//     TypDefName: _GUID  (020000B1)
//     Flags    : [NotPublic] [SequentialLayout] [Class] [Sealed]
[AnsiClass] [BeforeFieldInit]  (00100108)
//     Extends  : 0100000B [TypeRef] System.ValueType
//     Layout    : Packing:0, Size:16
//     CustomAttribute #1 (0c000275)
//     -------------------------------------------------------

Does anyone have a clue why this might be?
Thanks

Replies