Linking problem - bug? please help.

G

Gary Hughes

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<typename 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.
 
C

Carl Daniel [VC++ MVP]

Gary said:
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<typename 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?

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<typename 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
 
G

Gary Hughes

-----Original Message-----


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<typename 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


.

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.
 
C

Carl Daniel [VC++ MVP]

Gary said:
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.

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
 
M

Mahesh Hariharan[MSFT]

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top