Managed Compilation and the CC Runtime Library

Since the compiler switch /clr:safe does not support native types, safe assemblies do not depend on the C/C++ runtime library (CRT) at all. For the compilation models /clr and /clr:pure, only the DLL variants of the CRT are supported. Table 7-2 shows the compiler switches for choosing a variant of the CRT.

Table 7-2. C/C++ Runtime Variants

Compiler Switch

DLL or Static Lib

Debug

Compatible with /clr or /clr:pure?

Remarks

/MT

Static lib

No

No

Default setting when no /clr:* option is used

/MTd

Static lib

Yes

No

/MD

DLL

No

Yes

Default setting when /clr or /clr:pure is used

/MDd

DLL

Yes

Yes

Understanding the dependency between the C/C++ runtime and the managed compilation options is important because all linker inputs must either use the CRT in a consistent way or be independent of the CRT. You cannot combine linker inputs that have been compiled with different compiler switches for the CRT. If the project you want to migrate uses the DLL variant of the CRT already, there is no need to reconfigure that part of your project. When this is not the case, you have to touch all linker inputs that depend on the CRT. These linker inputs can either be object files or static libraries. To ensure that your object files don't cause trouble, compile all of them with /MD[d]. To ensure that the correct variants of static libraries are used, you have to modify the linker settings. Usually, all linker inputs except import libraries for DLLs depend on the CRT. Therefore, switching the CRT dependency can be a certain amount of work. If the static libraries your project depends on do not exist in variants that depend on the DLL variant of the CRT, you should leave your project as a native project and provide managed code extensions via a mixed-code DLL that you call from your native project.

Was this article helpful?

0 0

Post a comment