tags:

views:

550

answers:

3

Is it possible to use to use libs compiled with /MT in C++ CLR? It throws me either a ton of LNK2022 "metadata operation failed (8013118D)" errors (if I use /MD in the CLR project) or " '/MT' and '/clr:pure' command-line options are incompatible" if I use /MT.

What do I need to change in the library? The library is mine, but it includes several third party static libs.

+1  A: 

Can you try compiling with only /clr, not /clr:pure Thanks

mfawzymkh
+1  A: 

LNK2022 are a pain to pinpoint. It usually means one of your module's configuration affecting structure layout is different from the others.

Check for the following usual causes:

  • Make sure all your projects are using the same runtime library (/MDd or /MD) for your current solution configuration. If one project is using Debug while others are using Release or vice-versa, you will get LNK2022 errors.
  • Make sure all your projects are using the same structure member alignment. Pay special attention if one project is using /Zp switch. Also, make sure you dont use #pragma pack(n) conditionally.

You can use /d1reportSingleClassLayout_your-class-name_ (without space) to get information about the problematic class' layout.

For more information see : Diagnosing Hidden ODR Violations in Visual C++

Coincoin
Almost guaranteed to be /Zp or pragma pack.
consultutah
A: 

The only way I found to mix native code static libraries compiled with different crt runtime versions, is to write a DLL that acts like a bridge between the libraries. For example:

your.exe - compiled with /MD and clr yourbridge.dll - native, compiled with /MT and includes all the 3rd party libs built using /MT.

R Caloca