You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
helpviewer_keywords: ["cl.exe compiler, common language runtime option", "-clr compiler option [C++]", "clr compiler option [C++]", "/clr compiler option [C++]", "Managed Extensions for C++, compiling", "common language runtime, /clr compiler option"]
6
7
ms.assetid: fec5a8c0-40ec-484c-a213-8dec918c1d6c
7
8
---
8
-
# /clr (Common Language Runtime Compilation)
9
+
# `/clr` (Common Language Runtime Compilation)
9
10
10
11
Enables applications and components to use features from the common language runtime (CLR).
11
12
12
13
## Syntax
13
14
14
-
> **/clr**[**:**_options_]
15
+
> **`/clr`**\[**`:`**_options_]
15
16
16
17
## Arguments
17
18
18
-
*options*<br/>
19
-
One or more of the following switches, comma-separated.
19
+
*options*\
20
+
One or more of the following comma-separated arguments.
20
21
21
22
- none
22
23
23
-
With no options, **/clr** creates metadata for the application. The metadata can be consumed by other CLR applications, and enables the application to consume types and data in the metadata of other CLR components. For more information, see [Mixed (Native and Managed) Assemblies](../../dotnet/mixed-native-and-managed-assemblies.md).
24
+
With no options, **`/clr`** creates metadata for the application. The metadata can be consumed by other CLR applications, and enables the application to consume types and data in the metadata of other CLR components. For more information, see [Mixed (Native and Managed) Assemblies](../../dotnet/mixed-native-and-managed-assemblies.md).
24
25
25
-
-**pure**
26
+
-**`pure`**
26
27
27
-
**/clr:pure is deprecated**. The option is removed in Visual Studio 2017 and later. We recommend that you port code that must be pure MSIL to C#.
28
+
**`/clr:pure` is deprecated**. The option is removed in Visual Studio 2017 and later. We recommend that you port code that must be pure MSIL to C#.
28
29
29
-
-**safe**
30
+
-**`safe`**
30
31
31
-
**/clr:safe is deprecated**. The option is removed in Visual Studio 2017 and later. We recommend that you port code that must be safe MSIL to C#.
32
+
**`/clr:safe` is deprecated**. The option is removed in Visual Studio 2017 and later. We recommend that you port code that must be safe MSIL to C#.
32
33
33
-
-**noAssembly**
34
+
-**`noAssembly`**
34
35
35
-
**/clr:noAssembly is deprecated**. Use [/LN (Create MSIL Module)](ln-create-msil-module.md) instead.
36
+
**`/clr:noAssembly` is deprecated**. Use [`/LN` (Create MSIL Module)](ln-create-msil-module.md) instead.
36
37
37
-
Specifies that an assembly manifest should not be inserted into the output file. By default, the **noAssembly** option is not in effect.
38
+
Tells the compiler not to insert an assembly manifest into the output file. By default, the **`noAssembly`** option isn't in effect.
38
39
39
-
A managed program that does not have assembly metadata in the manifest is known as a *module*. The **noAssembly** option can be used only to produce a module. If you compile by using [/c](c-compile-without-linking.md) and **/clr:noAssembly**, then specify the [/NOASSEMBLY](noassembly-create-a-msil-module.md) option in the linker phase to create a module.
40
+
A managed program that doesn't have assembly metadata in the manifest is known as a *module*. The **`noAssembly`** option can be used only to produce a module. If you compile by using [`/c`](c-compile-without-linking.md) and **`/clr:noAssembly`**, then specify the [`/NOASSEMBLY`](noassembly-create-a-msil-module.md) option in the linker phase to create a module.
40
41
41
-
Before Visual Studio 2005, **/clr:noAssembly** required **/LD**. **/LD** is now implied when you specify **/clr:noAssembly**.
42
+
Before Visual Studio 2005, **`/clr:noAssembly`** required **`/LD`**. **`/LD`** is now implied when you specify **`/clr:noAssembly`**.
42
43
43
-
-**initialAppDomain**
44
+
-**`initialAppDomain`**
44
45
45
-
Enables a Visual C++ application to run on version 1 of the CLR. An application that is compiled by using **initialAppDomain**should not be used by an application that uses ASP.NET because it is not supported in version 1 of the CLR.
46
+
Enables a C++/CLI application to run on version 1 of the CLR. An application that's compiled by using **`initialAppDomain`**shouldn't be used by an application that uses ASP.NET because it's not supported in version 1 of the CLR.
46
47
47
-
-**nostdlib**
48
+
-**`nostdlib`**
48
49
49
-
Instructs the compiler to ignore the default \clr directory. The compiler produces errors if you are including multiple versions of a DLL such as System.dll. Using this option lets you specify the specific framework to use during compilation.
50
+
Instructs the compiler to ignore the default *`\clr`* directory. The compiler produces errors if you include multiple versions of a DLL, such as System.dll. This option lets you specify the specific framework to use during compilation.
50
51
51
52
## Remarks
52
53
53
-
Managed code is code that can be inspected and managed by the CLR. Managed code can access managed objects. For more information, see [/clr Restrictions](clr-restrictions.md).
54
+
Managed code is code that can be inspected and managed by the CLR. Managed code can access managed objects. For more information, see [`/clr `Restrictions](clr-restrictions.md).
54
55
55
-
For information about how to develop applications that define and consume managed types, see [Component Extensions for Runtime Platforms](../../extensions/component-extensions-for-runtime-platforms.md).
56
+
For information about how to develop applications that define and consume managed types in C++, see [Component Extensions for Runtime Platforms](../../extensions/component-extensions-for-runtime-platforms.md).
56
57
57
-
An application compiled by using **/clr** may or may not contain managed data.
58
+
An application compiled by using **`/clr`** may or may not contain managed data.
58
59
59
-
To enable debugging on a managed application, see [/ASSEMBLYDEBUG (Add DebuggableAttribute)](assemblydebug-add-debuggableattribute.md).
60
+
To enable debugging on a managed application, see [`/ASSEMBLYDEBUG` (Add DebuggableAttribute)](assemblydebug-add-debuggableattribute.md).
60
61
61
-
Only CLR types will be instantiated on the garbage-collected heap. For more information, see [Classes and Structs](../../extensions/classes-and-structs-cpp-component-extensions.md). To compile a function to native code, use the `unmanaged` pragma. For more information, see [managed, unmanaged](../../preprocessor/managed-unmanaged.md).
62
+
Only CLR types are instantiated on the garbage-collected heap. For more information, see [Classes and Structs](../../extensions/classes-and-structs-cpp-component-extensions.md). To compile a function to native code, use the `unmanaged` pragma. For more information, see [`managed`, `unmanaged`](../../preprocessor/managed-unmanaged.md).
62
63
63
-
By default, **/clr**is not in effect. When **/clr** is in effect, **/MD** is also in effect. For more information, see [/MD, /MT, /LD (Use Run-Time Library)](md-mt-ld-use-run-time-library.md). **/MD** ensures that the dynamically linked, multithreaded versions of the runtime routines are selected from the standard header (.h) files. Multithreading is required for managed programming because the CLR garbage collector runs finalizers in an auxiliary thread.
64
+
By default, **`/clr`**isn't in effect. When **`/clr`** is in effect, **`/MD`** is also in effect. For more information, see [`/MD`, `/MT`, `/LD` (Use Run-Time Library)](md-mt-ld-use-run-time-library.md). **`/MD`** ensures that the dynamically linked, multithreaded versions of the runtime routines are selected from the standard header files. Multithreading is required for managed programming because the CLR garbage collector runs finalizers in an auxiliary thread.
64
65
65
-
If you compile by using **/c**, you can specify the CLR type of the resulting output file with [/CLRIMAGETYPE](clrimagetype-specify-type-of-clr-image.md).
66
+
If you compile by using **`/c`**, you can specify the CLR type of the resulting output file by using the [`/CLRIMAGETYPE`](clrimagetype-specify-type-of-clr-image.md) linker option.
66
67
67
-
**/clr** implies **/EHa**, and no other **/EH** options are supported for **/clr**. For more information, see [/EH (Exception Handling Model)](eh-exception-handling-model.md).
68
+
**`/clr`** implies **`/EHa`**, and no other **`/EH`** options are supported for **`/clr`**. For more information, see [`/EH` (Exception Handling Model)](eh-exception-handling-model.md).
68
69
69
-
For information about how to determine the CLR image type of a file, see [/CLRHEADER](clrheader.md).
70
+
For information about how to determine the CLR image type of a file, see [`/CLRHEADER`](clrheader.md).
70
71
71
-
All modules passed to a given invocation of the linker must be compiled by using the same run-time library compiler option (**/MD** or **/LD**).
72
+
All modules passed to a given invocation of the linker must be compiled by using the same run-time library compiler option (**`/MD`** or **`/LD`**).
72
73
73
-
Use the [/ASSEMBLYRESOURCE](assemblyresource-embed-a-managed-resource.md) linker option to embed a resource in an assembly. [/DELAYSIGN](delaysign-partially-sign-an-assembly.md), [/KEYCONTAINER](keycontainer-specify-a-key-container-to-sign-an-assembly.md), and [/KEYFILE](keyfile-specify-key-or-key-pair-to-sign-an-assembly.md) linker options also let you customize how an assembly is created.
74
+
Use the [`/ASSEMBLYRESOURCE`](assemblyresource-embed-a-managed-resource.md) linker option to embed a resource in an assembly. [`/DELAYSIGN`](delaysign-partially-sign-an-assembly.md), [`/KEYCONTAINER`](keycontainer-specify-a-key-container-to-sign-an-assembly.md), and [`/KEYFILE`](keyfile-specify-key-or-key-pair-to-sign-an-assembly.md) linker options also let you customize how an assembly is created.
74
75
75
-
When **/clr** is used, the `_MANAGED` symbol is defined to be 1. For more information, see [Predefined Macros](../../preprocessor/predefined-macros.md).
76
+
When **`/clr`** is used, the `_MANAGED` symbol is defined to be 1. For more information, see [Predefined macros](../../preprocessor/predefined-macros.md).
76
77
77
-
The global variables in a native object file are initialized first (during DllMain if the executable is a DLL), and then the global variables in the managed section are initialized (before any managed code is run). `#pragma`[init_seg](../../preprocessor/init-seg.md) only affects the order of initialization in the managed and unmanaged categories.
78
+
The global variables in a native object file are initialized first (during `DllMain` if the executable is a DLL), and then the global variables in the managed section are initialized (before any managed code is run). [`#pragmainit_seg`](../../preprocessor/init-seg.md) only affects the order of initialization in the managed and unmanaged categories.
78
79
79
-
## Metadata and Unnamed Classes
80
+
###Metadata and Unnamed Classes
80
81
81
-
Unnamed classes will appear in metadata named as follows:`$UnnamedClass$`*crc-of-current-file-name*`$`*index*`$`, where *index* is a sequential count of the unnamed classes in the compilation. For example, the following code sample generates an unnamed class in metadata.
82
+
Unnamed classes appear in metadata under names such as `$UnnamedClass$<crc-of-current-file-name>$<index>$`, where `<index>` is a sequential count of the unnamed classes in the compilation. For example, the following code sample generates an unnamed class in metadata.
82
83
83
84
```cpp
84
85
// clr_unnamed_class.cpp
@@ -88,7 +89,21 @@ class {} x;
88
89
89
90
Use ildasm.exe to view metadata.
90
91
92
+
### To set this compiler option in the Visual Studio development environment
93
+
94
+
1. Open the project's **Property Pages** dialog box. For details, see [Set C++ compiler and build properties in Visual Studio](../working-with-project-properties.md).
95
+
96
+
1. Set the **Configuration** dropdown to **All configurations**, and set the **Platform** dropdown to **All Platforms**.
97
+
98
+
1. Select the **Configuration Properties** > **Advanced** page.
99
+
100
+
1. Modify the **Common Language Runtime Support** property. Choose **OK** to save your changes.
101
+
102
+
### To set this compiler option programmatically
103
+
104
+
- See <xref:Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool.CompileAsManaged>.
0 commit comments