cl.exe command way to compile CPP

Source: Internet
Author: User
Tags microsoft c intel pentium

Calling CL-compiled CPP files directly in the command-line window often fails.

The main reason is that some header files and executables are not set in the environment variables. You can VSVAR32.BAT批处理文件 set the environment variables by execution, note that the placement of vs2005 with 2008 may be different, if not the current path cl.exe, you can go to the/common7/tools directory to look for.

The batch file is primarily an environment variable that is temporarily configured by the SET command, so the bat file needs to be rerun to execute the CL command after booting.

Additional CL command instructions for use

CL.exe is a 32-bit tool that controls the Microsoft C and C + + compilers and linker. The compiler produces a common object file format (COFF) object (. obj) file. The linker produces an executable file (. exe) or a dynamic-link library file (DLL).

Note that all compiler options are case-sensitive.

To compile but not link, use/C.

Use NMAKE to generate the output file.

Use the BSCMAKE support class to browse.

The following is a complete list of compiler option classifications.

Optimization

Option action
/o1 Creating Small Code
/o2 Creating Fast Code
/oa assumes no aliases
/ob Controlling inline expansion
/od Disabling optimizations
/og using global optimization
/oi Generating intrinsic functions
/op Improving floating point consistency
/os Code Size First
/ot Code Speed First
/ow assumes that aliases are used in function calls
/OX using maximum optimization (/OB1GITY/GS)
/oy Omit frame pointer

Code generation

Option action
/CLR enables Managed Extensions for C + + and produces output files that run on the common language runtime
/eh specifying an exception handling model
/g3 optimizes the code to optimize the 386 processor. is disabled in Visual C + + 5.0, the compiler ignores this option
/g4 optimizes the code to optimize the 486 processor. is disabled in Visual C + + 5.0, the compiler ignores this option
/G5 optimized code to optimize Pentium
/GB is equivalent to/g6; Set the value of _m_ix86 to 600
/GD using the __cdecl calling convention
/ge activating the stack probe
/gf
/GF enabling string pooling
/gh Call hook function _penter
/gh Call hook function _pexit
/GL Enable full program optimization
/GM Enable minimal rebuild
/GR Enable run-time type information (RTTI)
/GR using the __fastcall calling convention
/GS Control stack probing
/GT supports fiber security for data allocated using static thread local storage
/GX Enable synchronous exception handling
/gy enabling function-level linking
/GZ using the __stdcall calling convention
/MD creating multithreaded DLLs with MSVCRT.lib
/MDd using MSVCRTD.lib to create a debug multithreaded DLL
/ML using LIBC.lib to create a single-threaded executable file
/MLd creating a debug single-threaded executable file using LIBCD.lib
/MT creating multithreaded Executables with LIBCMT.lib
/MTD using LIBCMTD.lib to create a debug multithreaded executable file

Output file

Option action
/fa
/FA Creating assembly Files
Set list file name
/FD Renaming program database files
/fe renaming an executable file
/FM Creating a mapping file
/FO creating an Object file
/fp specifying the precompiled header file name
/fr
/FR Generating Browser files
/fx to merge the inserted code with the source file

Debugging

Option action
/GS Buffer Security check
/GZ is the same as/RTC1
/RTC Enable run-time error checking
/WP64 Detecting 64-bit portability issues
/yd to put complete debugging information in all object files
/yl inserting a PCH reference when creating a debug library
/Z7 generating debug information that is compatible with C 7.0
/zd Generating Line numbers
/ZI Generating Complete Debug information

Preprocessor

Option action
/AI Specifies the directory to search for when parsing a file reference passed to the #using directive
/C preserves annotations during preprocessing
/d defines constants and macros
/e Copy the pre-processor output to standard output
/EP Copy the pre-processor output to standard output
/FL preprocessing the specified include file
/FU enforces the use of the file name as if it had been passed to the #using directive
/I search the directory for include files
/p writes the preprocessor output to a file
/u Remove a predefined macro
/U removes all pre-defined macros
/x ignores standard include directories
/ZI to include debug information in a program database that is compatible with edit and continue

Language

Option action
/nobool Suppress C + + bool, true, and False keywords
/VD to cancel or enable a hidden Vtordisp class member
/VMB use the best base for pointers to members
/VMG use a fully generic pointer to pointers to members
/VMM declaring multiple inheritance
/vms declaring single inheritance
/VMV declaring virtual inheritance
/za Disabling language extensions
/zc specifying standard behavior under/ze
/ze Enabling language Extensions
/ZG generating function prototypes
/zl removing the default library name from the. obj file
/ZP N Package Structure members
/zs Check Grammar only

Link

Option action
/F Sets the stack size
/LD Creating a dynamic-link library
/ldd Creating a Debug dynamic-link library
/link passes the specified options to the link
/MD compiling with MSVCRT.lib to create a multithreaded DLL
/MDd compiling with MSVCRTD.lib to create a debug multithreaded DLL
/ML compiling with LIBC.lib to create a single-threaded executable file
/MLD compiling with LIBCD.lib to create a debug single-threaded executable file
/MT compiling with LIBCMT.lib to create a multithreaded executable file
/MTD using LIBCMTD.lib compilation to create a debug multithreaded executable file

Precompiled header

Option action
/y-ignores all other precompiled header compiler options in the current build
/yc Creating Precompiled Header Files
/yd to put complete debugging information in all object files
/yu using precompiled header files during build
/YX automatically handles precompiled headers

Miscellaneous

Option action
@ Specify Response file
/? List Compiler Options
/C compiled but not linked
/h limits the length of external (public) names
/help List Compiler Options
/j changing the default char type
/nologo Display Login Banner
/qi0f Make sure Pentium 0F instructions are no problem
Workarounds for/QIfdiv FDIV, Fprem, Fptan, and Fpatan directives for defective Intel Pentium microprocessors
QIfist call to cancel the Helper function _ftol when you need to convert from a floating-point type to an integral type
/showincludes displays a list of all included files during compilation
/tc
/TC specifying C source files
/tp
/TP specifying C + + source files
/V Set version string
/w Setting the warning level
/w Disable all warnings
/wall enable all warnings, including warnings that are disabled by default
/WL single-line diagnostics to enable error messages and warning messages when compiling C + + source code from the command line
/ZM setting the compiler's memory allocation limit


The CL command line uses the following syntax:

CL [option ...] file ... [option | file] ... [Lib ...] [@command-file] [/link link-opt ...]

The following table describes the entry meaning of the CL command

Option one or more CL options. Note that all options are applied to all specified source files. The option is specified by a forward slash (/) or a dash (–). If an option has parameters, the description of the option specifies whether spaces are allowed between options and parameters. Option names (except for the/help option) are case-sensitive. For more information, see the Order of CL options.

File the name of one or more source files,. obj files, or libraries. CL compiles the source file and passes the name of the. obj file and library to the linker. For more information, see CL file name syntax.

Lib one or more library names. CL passes these names to the linker.

Command-file files that contain multiple options and file names. For more information, see CL command file.

Link-opt one or more linker options. CL passes these options to the linker.

You can specify any number of options, file names, and library names, provided that the number of characters on the command line does not exceed 1024, which is specified by the operating system.



CL command file See
Set Compiler Options | Compiler options
A command file is a text file that contains the options and file names that you type on the command line or that you specify with the CL environment variable. CL accepts a compiler command file that is used as a parameter in the CL environment variable or on the command line. Unlike command-line or CL environment variables, the command file allows multiple lines of options and file names to be used.

The options and file names in the command file are processed according to the location of the CL environment variable or the command file name on the command line. However, if the/link option appears in the command file, all options for the remainder of the line are passed to the linker. The options in the following lines of the command file and the options after the command file call on the command line are still accepted as compiler options.

The command file must not contain the CL command. Each option must start and end on the same line; You cannot use a backslash (") to combine an option across rows.

The command file is specified with an @ character followed by a file name, which specifies an absolute path or a relative path.

cl.exe command way to compile CPP

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.