/CLR (Common Language Runtime Library compilation)

Source: Internet
Author: User
Tags hosting

From http://msdn.microsoft.com/zh-cn/library/k8d11d4s.aspx

Enables applications and components to use functions in the Common Language Runtime Library (CLR.

/clr[:options]
Parameters

Options

Use commas (,) to separate one or more of the following options:

/CLR

Create metadata for your applications that can be used by other CLR applications and allow your applications to use the types and data in the metadata of other CLR components.

For more information, see:

  • Hybrid (local and hosted) Assembly

  • How to: migrate to/CLR

/CLR: pure

Generate an output file containing only msil, which does not contain any executable code on the local machine, but can contain the native type compiled into msil.

For more information, see pure code and verifiable code.

/CLR: safe

Generate an output file that only contains msil (no local executable code) and is verifiable./CLR: safeEnable verification diagnostics (peverify tool (peverify.exe )).

For more information, see writing code that can be verified as type security.

/CLR: oldsyntax

Enable managed extensions for the c ++ syntax (the original visual c ++ syntax for CLR programming.

Note:In Microsoft Visual C ++ 2005, the C ++ managed extension syntax has been rejected. You must use/CLR: oldsyntax. To develop a new application, use the updated syntax. For more information, see new C ++ language features.

If you have a hosted extension for C ++ applications, you can start to dock your project to use the new syntax. For more information, see porting and upgrading programs.

/CLR: noassembly

NoassemblyOption specifies that the Assembly list should not be inserted into the output file. By default,NoassemblyOption does not work.

Note:In Visual C ++ 2005, it has been rejectedNoassembly. Use/ln instead (create msil module ). For more information, see compiler options not recommended in Visual C ++ 2005.

A managed program that does not contain Assembly metadata in the list is called a "module ".NoassemblyOption can only be used to generate modules. If/C (compiled but not linked) and/CLR: noassemblyTo create a module, specify the/noassembly (create msil module) option in the linker stage.

Before the Visual C ++ 2005,/CLR: noassemblySuggestion/CLR. However, now/CLRAlso supported/CLR: oldsyntaxTherefore, you must specify/CLR: noassemblySpecify/CLRFormat. For example,/CLR: noassembly/CLRUse the New Visual C ++ CLR syntax to create a module./CLR: noassembly, oldsyntaxUse the C ++ hosting extension to create a module.

Before the Visual C ++ 2005,/CLR: noassemblyYes/LD. And now/LDBy specifying/CLR: noassembly.

/CLR: initialappdomain

Allows visual c ++ applications to run in the public Language Runtime Library version 1. If you useInitialappdomainFor more information, see the questions discussed in the Knowledge Base Article q309694. Can I find the msdn Library Media or http://support.microsoft.com/default.aspx? Ln = ZH-CN.

UseInitialappdomainCompiled applications should never be used by ASP. NET applications. Upgrade to a newer Runtime Library to execute ASP. NET tasks in C ++.

Remarks

Managed code is the code that can be checked and managed by the Common Language Runtime Library. Managed code can access managed objects.

For more information, see/CLR restrictions.

For information about how to develop and define and use hosted applications, see new C ++ language features.

Use/CLRThe compiled application may or may not contain hosted data.

To allow debugging in a hosted application, see/assemblydebug (add debuggableattribute ).

Only the CLR type will be instantiated in the garbage collection heap. For more information, see classes and structs (managed ). To compile a function into local code, use unmanaged. For more information, see manage, unmanage.

By default,/CLRInvalid. When/CLREffective,/MDIt will also take effect (for more information, see/MD )./MDMake sure that the multi-threaded version of the dynamic link of the running library routine is selected from the Standard Header (. h) file. Multi-threaded processing is required for hosting programming. Part of the reason is that the CLR garbage collector will run the terminator in the auxiliary thread.

If you use/CYou can use/clrimagetype (specifying the CLR image type) to specify the CLR type (ijw type, security type, or pure type) of the generated output file ).

/CLRImplied/EHA, Other/EhOption and/CLR. For more information, see/EH (Exception Handling Model ).

For details about how to determine the CLR image type of a file, see/clrheader.

You must use the same Runtime Library compiler option (/MDOr/LD) Compile and pass to all modules called by the given linker.

Use the/assemblyresource (embedded Managed Resource) linker option to embed Resources in the Assembly. /Delaysign (partial signature for the assembly),/keycontainer (specify the key container to sign the Assembly), And/Keyfile (specify the key or key pair to sign the Assembly) the linker option can also be used to customize how an assembly is created.

Use/CLR,_ ManagedThe symbol is defined as 1. For more information, see predefined macros.

First, you will initialize the global variables in the local object file (if the executable file is DLL, it will be in the dllmain period), and then initialize the global variables in the hosted part (before running any managed code ). # Pragma init_seg only affects the initialization sequence in managed and unmanaged categories.

Use/CLR: safeCompiling is similar to using/platform: anycpu for languages such as C.

Security images and pure Images

The pure image uses the CLR version of the C Runtime Library. However, CRT cannot be verified, so use/CLR: safeYou cannot use CRT when compiling. For more information, see C run-time libraries.

Examples of native code that cannot appear in a pure image include inline assembly, setjmp, or longjmp.

Each entry point of a pure image or security image is hosted. Use/CLRDuring compilation, the entry point is the local entry point. For more information, see _ clrcall.

Use/CLR: safeDuring compilation, the variable is within the appdomain by default, and cannot be based on each process. Use/CLR: pure,AppdomainThe default value, but the process variable can be used.

Run and use in a 64-bit Operating System/CLROr/CLR: pureWhen the 32-bit. EXE file is compiled, the application runs under wow64, and wow64 allows 32-bit CLR to run the 32-bit application in the 64-bit operating system. By default/CLR: safeThe compiled. exe will be run in the 64-bit CLR of the computer running the 64-bit operating system (in the 32-bit operating system, the same. exe will run in the 32-bit CLR ). However, security applications can load 32-bit components. In this case, when the security image loads a 32-bit application, the security image running with the 64-bit support of the operating system will fail (badformatexception ). To ensure that the security image continues running when loading a 32-bit image in a 64-bit operating system, you must use/clrimagetype (specifying the CLR image type) to change the metadata (. and mark it as running under wow64. The following is an example of a command line (replacing your own input symbol ):

CL/CLR: Safe T. CPP/link/clrimagetype: Pure/entry :? Main $ hymhxz/subsystem: Console

For information on obtaining modifier names, see view modifier names in the Use List. For more information about 64-bit programming, see 64-bit programming (how to implement-Visual C ++ ).

For examples, rehearsals, and more information, see:

  • Walkthrough: Use/CLR: pure

  • How to: migrate to/CLR: pure

  • Cpplangfeat example: language function Overview

  • Pure and verifiable code

Metadata and untitled classes

The Untitled class is displayed in the metadata in the name format as follows:$ Unnamedclass $CRC of the current file name$Index$"Index" indicates the sequence number of the Untitled class during compilation. For example, the following code example generates an unnamed class in the metadata:

Copy code
// clr_unnamed_class.cpp// compile with: /clr /LDclass {} x;

Use ildasm.exe to view metadata.

Set this compiler option in the Visual Studio development environment
  1. Open the "properties" dialog box of the project. For more information, see How to: Open the project properties page.

  2. Click the "Configure properties" folder.

  3. Click the general property page.

  4. Modify the "support for common language runtime libraries" attribute.

    For information about how to create a module, see/noassembly (create an msil module ).

    Note:

    In the properties page dialog box of the project, enable/CLRAnd/CLRIncompatible compiler option attributes will also be adjusted as needed. For example, if you set/RTCAnd enable/CLR,/RTCWill be disabled.

    In addition, debugging/CLRFor applications, the "Debugger type" attribute should be set to "hybrid" or "managed only ". For more information, see C ++ debugging configuration project settings.

Set this compiler option programmatically
  • See compileasmanaged.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.