Statically linked unmanaged libraries and the C ++ CLR
Can I use libs compiled with / MT in C ++ CLR? This throws me a ton of LNK2022 "Metadata processing error (8013118D)" (if I use / MD in a CLR project), or the command line options "/ MT" and "/ clr: pure" 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 libraries.
a source to share
LNK2022 is a pain to pinpoint. This usually means that one of the settings in your module that affects the structure of the structure is different from the others.
Check for the following common reasons:
- Make sure all of your projects use 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 errors LNK2022.
- Make sure all of your projects use the same alignment of structure elements. Pay special attention if one project uses the / Zp switch. Also, make sure you are not using #pragma pack (n) conditionally.
You can use / d 1reportSingleClassLayout_your-class-name_ (no space) to get information about the layout of the problematic class.
For more information, see Diagnosing Hidden ODR Violations in Visual C ++
a source to share
The only way I have found to mix native static code libraries compiled with different versions of crt runtime is to write a DLL that acts as a bridge between the libraries. For instance:
your.exe is compiled with / MD and clr yourbridge.dll is native, compiled with / MT and includes all 3rd party libraries built with / MT.
a source to share