Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mixing code compiled with /MT and /MD

I have a large body of code, compiled with /MT (i.e. expecting to statically link against the CRT). I need to combine this with a static third-party library, which has been built with /MD (i.e. expecting to link the CRT dynamically).

Is it theoretically possible to link the two into one executable without recompiling either?

If I link with /nodefaultlib:msvcrt, I end up with a small number of undefined references to things like __imp__wgetenv. I'm tempted to try implementing those functions in my own code, forwarding to wgetenv, etc. Is that worth trying, or will I run straight into the next problem?

Unfortunately I'm Forbidden from taking the easy option of packing the thirdparty code into a separate DLL :-/

like image 921
slowdog Avatar asked Aug 12 '10 16:08

slowdog


1 Answers

No. /MT and /MD are mutually exclusive.

All modules passed to a given invocation of the linker must have been compiled with the same run-time library compiler option (/MD, /MT, /LD).

Source

like image 109
ChrisF Avatar answered Oct 04 '22 05:10

ChrisF