Linking problem - bug? please help.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gary Hughes

    #1

    Linking problem - bug? please help.

    Hi all, sometime I posted a problem in here where I was
    getting the following error from the linker in VS C++ 2003.

    Linking...
    GCClass.obj : error LNK2022: metadata operation failed
    (80131188) : Inconsistent field declarations in duplicated
    types (types: GCClass; fields: m_blah): (0x04000001).
    LINK : fatal error LNK1215: metadata operation failed
    (80131130) :

    At the time I was unable to produce a simple test case and
    due to time constraints I had to leave the problem. I had
    another go at it today and was able to produce a simple
    test case. The code follows:

    namespace itga
    {

    template<typena me Type>
    class dog
    {
    public:
    class blah {};
    };

    }

    public __gc class GCClass
    {
    itga::dog<int>: :blah* m_blah;
    };

    If I attempt to instantiate GCClass as follows I get the
    error above.

    GCClass* g = new GCClass;

    There are two things I can do to get rid of the error:

    1. put the dog class outside the itga namespace.
    2. not make the dog class a template.

    Neither of these is possible nor desirable as I'm just
    trying to wrap a heap of existing C++ code in .NET
    wrappers and as far as I am concerned this seems perfectly
    legal to me.

    Does anyone have any idea what is going on here?

    thanks.

    Gary.


  • Carl Daniel [VC++ MVP]

    #2
    Re: Linking problem - bug? please help.

    Gary Hughes wrote:[color=blue]
    > Hi all, sometime I posted a problem in here where I was
    > getting the following error from the linker in VS C++ 2003.
    >
    > Linking...
    > GCClass.obj : error LNK2022: metadata operation failed
    > (80131188) : Inconsistent field declarations in duplicated
    > types (types: GCClass; fields: m_blah): (0x04000001).
    > LINK : fatal error LNK1215: metadata operation failed
    > (80131130) :
    >
    > At the time I was unable to produce a simple test case and
    > due to time constraints I had to leave the problem. I had
    > another go at it today and was able to produce a simple
    > test case. The code follows:
    >
    > namespace itga
    > {
    >
    > template<typena me Type>
    > class dog
    > {
    > public:
    > class blah {};
    > };
    >
    > }
    >
    > public __gc class GCClass
    > {
    > itga::dog<int>: :blah* m_blah;
    > };
    >
    > If I attempt to instantiate GCClass as follows I get the
    > error above.
    >
    > GCClass* g = new GCClass;
    >
    > There are two things I can do to get rid of the error:
    >
    > 1. put the dog class outside the itga namespace.
    > 2. not make the dog class a template.
    >
    > Neither of these is possible nor desirable as I'm just
    > trying to wrap a heap of existing C++ code in .NET
    > wrappers and as far as I am concerned this seems perfectly
    > legal to me.
    >
    > Does anyone have any idea what is going on here?[/color]

    There's more to it than what you posted. Taking your sample code above and
    making it into a complete program:

    #using <mscorlib.dll >

    namespace itga
    {

    template<typena me Type>
    class dog
    {
    public:
    class blah {};
    };

    }

    public __gc class GCClass
    {
    itga::dog<int>: :blah* m_blah;
    };

    int main()
    {
    GCClass* g = new GCClass;
    }

    compiing with cl -clr compiles and links without incident. Can you post a
    complete example along with compiler command-line options?

    -cd


    Comment

    • Gary Hughes

      #3
      Re: Linking problem - bug? please help.

      [color=blue]
      >-----Original Message-----
      >Gary Hughes wrote:[color=green]
      >> Hi all, sometime I posted a problem in here where I was
      >> getting the following error from the linker in VS C++[/color][/color]
      2003.[color=blue][color=green]
      >>
      >> Linking...
      >> GCClass.obj : error LNK2022: metadata operation failed
      >> (80131188) : Inconsistent field declarations in[/color][/color]
      duplicated[color=blue][color=green]
      >> types (types: GCClass; fields: m_blah): (0x04000001).
      >> LINK : fatal error LNK1215: metadata operation failed
      >> (80131130) :
      >>
      >> At the time I was unable to produce a simple test case[/color][/color]
      and[color=blue][color=green]
      >> due to time constraints I had to leave the problem. I[/color][/color]
      had[color=blue][color=green]
      >> another go at it today and was able to produce a simple
      >> test case. The code follows:
      >>
      >> namespace itga
      >> {
      >>
      >> template<typena me Type>
      >> class dog
      >> {
      >> public:
      >> class blah {};
      >> };
      >>
      >> }
      >>
      >> public __gc class GCClass
      >> {
      >> itga::dog<int>: :blah* m_blah;
      >> };
      >>
      >> If I attempt to instantiate GCClass as follows I get the
      >> error above.
      >>
      >> GCClass* g = new GCClass;
      >>
      >> There are two things I can do to get rid of the error:
      >>
      >> 1. put the dog class outside the itga namespace.
      >> 2. not make the dog class a template.
      >>
      >> Neither of these is possible nor desirable as I'm just
      >> trying to wrap a heap of existing C++ code in .NET
      >> wrappers and as far as I am concerned this seems[/color][/color]
      perfectly[color=blue][color=green]
      >> legal to me.
      >>
      >> Does anyone have any idea what is going on here?[/color]
      >
      >There's more to it than what you posted. Taking your[/color]
      sample code above and[color=blue]
      >making it into a complete program:
      >
      >#using <mscorlib.dll >
      >
      >namespace itga
      >{
      >
      >template<typen ame Type>
      >class dog
      >{
      >public:
      > class blah {};
      >};
      >
      >}
      >
      >public __gc class GCClass
      >{
      > itga::dog<int>: :blah* m_blah;
      >};
      >
      >int main()
      >{
      > GCClass* g = new GCClass;
      >}
      >
      >compiing with cl -clr compiles and links without[/color]
      incident. Can you post a[color=blue]
      >complete example along with compiler command-line options?
      >
      >-cd
      >
      >
      >.
      >[/color]

      Sorry Carl, one thing I did not mention main() needs to be
      in a separate file the class #included. I can send you a
      complete project if you like. If the whole thing is in a
      single cpp file it works correctly as you found.

      Gary.


      Comment

      • Carl Daniel [VC++ MVP]

        #4
        Re: Linking problem - bug? please help.

        Gary Hughes wrote:[color=blue]
        > Sorry Carl, one thing I did not mention main() needs to be
        > in a separate file the class #included. I can send you a
        > complete project if you like. If the whole thing is in a
        > single cpp file it works correctly as you found.[/color]

        ZIP it up and post it here, or you can email to me - your choice. Do the
        obvious things to my reply-to address to get a real email address.

        -cd


        Comment

        • Mahesh Hariharan[MSFT]

          #5
          Re: Linking problem - bug? please help.

          i work with c++ team, i created two files, one header file with your class
          and one cpp which #Includes the header, but we cannot repro it.
          It will be great if you can send the repro project to my email address.
          (remove the online ,from my address) or post a better repro. We would like
          to understand as to why this doesn't work.
          Mahesh
          --------------------[color=blue]
          >Content-Class: urn:content-classes:message
          >From: "Gary Hughes" <geh@itga.com.a u.NOSPAM>
          >Sender: "Gary Hughes" <geh@itga.com.a u.NOSPAM>
          >References: <076601c39c35$b d537970$a001280 a@phx.gbl>[/color]
          <OUFrrjDnDHA.36 12@TK2MSFTNGP11 .phx.gbl>[color=blue]
          >Subject: Re: Linking problem - bug? please help.
          >Date: Sun, 26 Oct 2003 19:27:11 -0800
          >Lines: 103
          >Message-ID: <042f01c39c3a$3 5b50d80$a301280 a@phx.gbl>
          >MIME-Version: 1.0
          >Content-Type: text/plain;
          > charset="iso-8859-1"
          >Content-Transfer-Encoding: 7bit
          >X-Newsreader: Microsoft CDO for Windows 2000
          >X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
          >Thread-Index: AcOcOjW1YYj2fjz USJeDNUBJ8gfyXA ==
          >Newsgroups: microsoft.publi c.dotnet.langua ges.vc
          >Path: cpmsftngxa06.ph x.gbl
          >Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.vc:29763
          >NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
          >X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vc
          >
          >[color=green]
          >>-----Original Message-----
          >>Gary Hughes wrote:[color=darkred]
          >>> Hi all, sometime I posted a problem in here where I was
          >>> getting the following error from the linker in VS C++[/color][/color]
          >2003.[color=green][color=darkred]
          >>>
          >>> Linking...
          >>> GCClass.obj : error LNK2022: metadata operation failed
          >>> (80131188) : Inconsistent field declarations in[/color][/color]
          >duplicated[color=green][color=darkred]
          >>> types (types: GCClass; fields: m_blah): (0x04000001).
          >>> LINK : fatal error LNK1215: metadata operation failed
          >>> (80131130) :
          >>>
          >>> At the time I was unable to produce a simple test case[/color][/color]
          >and[color=green][color=darkred]
          >>> due to time constraints I had to leave the problem. I[/color][/color]
          >had[color=green][color=darkred]
          >>> another go at it today and was able to produce a simple
          >>> test case. The code follows:
          >>>
          >>> namespace itga
          >>> {
          >>>
          >>> template<typena me Type>
          >>> class dog
          >>> {
          >>> public:
          >>> class blah {};
          >>> };
          >>>
          >>> }
          >>>
          >>> public __gc class GCClass
          >>> {
          >>> itga::dog<int>: :blah* m_blah;
          >>> };
          >>>
          >>> If I attempt to instantiate GCClass as follows I get the
          >>> error above.
          >>>
          >>> GCClass* g = new GCClass;
          >>>
          >>> There are two things I can do to get rid of the error:
          >>>
          >>> 1. put the dog class outside the itga namespace.
          >>> 2. not make the dog class a template.
          >>>
          >>> Neither of these is possible nor desirable as I'm just
          >>> trying to wrap a heap of existing C++ code in .NET
          >>> wrappers and as far as I am concerned this seems[/color][/color]
          >perfectly[color=green][color=darkred]
          >>> legal to me.
          >>>
          >>> Does anyone have any idea what is going on here?[/color]
          >>
          >>There's more to it than what you posted. Taking your[/color]
          >sample code above and[color=green]
          >>making it into a complete program:
          >>
          >>#using <mscorlib.dll >
          >>
          >>namespace itga
          >>{
          >>
          >>template<type name Type>
          >>class dog
          >>{
          >>public:
          >> class blah {};
          >>};
          >>
          >>}
          >>
          >>public __gc class GCClass
          >>{
          >> itga::dog<int>: :blah* m_blah;
          >>};
          >>
          >>int main()
          >>{
          >> GCClass* g = new GCClass;
          >>}
          >>
          >>compiing with cl -clr compiles and links without[/color]
          >incident. Can you post a[color=green]
          >>complete example along with compiler command-line options?
          >>
          >>-cd
          >>
          >>
          >>.
          >>[/color]
          >
          >Sorry Carl, one thing I did not mention main() needs to be
          >in a separate file the class #included. I can send you a
          >complete project if you like. If the whole thing is in a
          >single cpp file it works correctly as you found.
          >
          >Gary.
          >
          >
          >[/color]

          Comment

          Working...