Sign in to follow this  

[.net] native/unmaged C++/CLI

This topic is 3742 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I recently added some new code files to a C++/CLI project. The added code is all native. I simply added the code to the project and built it. It compiled fine but I am getting the linker error: LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (IDirect3DDevice9): (0x0200015b) I get this in three .obj files. Each file has a different class, but each class holds a member to an IDirect3DDevice9 pointer. But I'm not sure why this throws a LNK2022 error, which seems to have to do with defining classes of the same name.

Share this post


Link to post
Share on other sites
From the MSDN:
Quote:

Error Message
metadata operation failed (HRESULT) : error_message

The linker detected an error while merging metadata. The metadata errors must be resolved to link successfully.

One way to diagnose this problem is to run ildasm –tokens on the object files to find which types have the tokens listed in error_message, and look for differences. In metadata, two different types with the same name is not valid, even if the just LayoutType attribute is different.

One reason for LNK2022 is when a type (such as a struct) exists in multiple compilands with the same name, but with conflicting definitions, and when you compile with /clr. In this case, make sure that the type has an identical definition in all compilands. The type name is listed in error_message.

Another possible cause for LNK2022 is when the linker finds a metadata file in a different location than was specified to the compiler (with #using ). Make sure that the metadata file (.dll or .netmodule) is in the same location when passed to the linker, as it was when it was passed to the compiler.



Skizz

Share this post


Link to post
Share on other sites
It compiles and links if I comment out #include <d3dx9.h>

//#include <d3dx9.h> // works now
#include "Box.h" // Box.h #includes <d3dx9.h> too
#include <fstream>

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

...

Can anyone explain this?

Share this post


Link to post
Share on other sites
Quote:
Original post by Quat
It compiles and links if I comment out #include <d3dx9.h>

//#include <d3dx9.h> // works now
#include "Box.h" // Box.h #includes <d3dx9.h> too
#include <fstream>

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

...

Can anyone explain this?


that seems to match up pretty well to this description:
Quote:

One reason for LNK2022 is when a type (such as a struct) exists in multiple compilands with the same name, but with conflicting definitions, and when you compile with /clr. In this case, make sure that the type has an identical definition in all compilands. The type name is listed in error_message.

Share this post


Link to post
Share on other sites

This topic is 3742 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this