Command Line usage of CL and link

Source: Internet
Author: User
Tags microsoft c

Cl.exe is a 32-bit tool that controls Microsoft C and C ++ compilers and connectors. The compiler generates a Common Object File Format (coff)
Object (. OBJ. The linker generates an executable file (.exe) or a dynamic link library file (DLL ).

Note that all compiler options are case sensitive.
The usage is as follows:
Cl [option...] file... [Option | file]... [Lib...] [@ command-file] [/link-opt...]

Option: one or more Cl options. Note that all options are applied to all specified source files. The
A forward slash (/) or A hyphen. If an option has a parameter, the description of this option refers
Whether spaces are allowed between options and parameters. The option name (except for the/help option) is case sensitive. Related
For more information, see the order of CL options.
/C: compiled but not linked
/Zs: Check the syntax
/? : List compiler options
/Arch: Use the SSE or sse2 command to generate code
/Arch: sse2
/CLR: Enable the C ++ hosting extension and generate output files running on the Common Language Runtime Library
/F: Set the stack size | this option sets the program stack size (in bytes ).
If this option is not used, the default stack size is 1 MB.
/F 100
/Fe: Rename the executable file
/Feexe.exe
/G7: Code optimized for Pentium 4 or athlon.
/GA: optimizes the code of Windows applications.
/GL: enable full-Program Optimization
/GM: Minimum regenerate Enabled
/Help: List compiler options
/I: Search for include files in the directory | specify the source file directory include
/I "E:/VC/include"
/Link: Pass the specified option to link
/MD: Use msvcrt. lib to create multi-thread DLL
/Ml: Use libc. lib to create a single-thread Executable File
/MT: Use libcmt. lib to create multi-thread executable files
/O1: create small code
/O2: create quick code
/OS: code size first
/W: Set the warning level
/W3
------------------------------
/OT: Code speed first
/Ld: create a dynamic link library
/Ox: Maximum Optimization

/Zs: only check the syntax
------------------------------
/TC: Specifies the C source file
/TP: Specifies the C ++ source file
Bytes -----------------------------------------------------------------------------------------
File: the name of one or more source files,. OBJ files, or libraries. CL compiles the source file and name the. OBJ file and library.
The name is passed to the linker. For more information, see CL file name syntax.
Lib: name of one or more databases. CL passes these names to the linker.
Command-file: a file that contains multiple options and file names. For more information, see the CL command file.
Link-OPT: one or more Linker Options. CL passes these options to the linker
Bytes ---------------------------------------------------------------------------------------------
Classic usage:
Cl *. CPP/G7/MD/Ox/OT/W3/C/ehs/ I "G:/Visual C ++/vc98/platformsdk/include"
Bytes ---------------------------------------------------------------------------------------------
Link links common object file formats (coff) object files with libraries to create 32-bit executable (.exe) files or Dynamic Links
Library (DLL) 32-Bit Tool.

Link usage:

/Align specifies the alignment of each section
The/align option specifies the alignment of each section in the linear address space of the program. The number parameter is in bytes and must be a power of 2. The default value is 4 K (4096 ). If alignment is generated
If the image is invalid, the linker issues a warning. Unless
Compile an application such as a device driver. Otherwise, you do not need to modify the alignment mode.
/DLL generation DLL
/Driver: Create a driver in Windows NT core Mode
/Exetype generate Virtual Device Driver
/Exetype: Dynamic creates a Dynamically Loaded Virtual Device Driver.
/Exetype: dev386 creates a statically loaded Virtual Device Driver. This is the default value of/exetype.
/Incremental control incremental links
/Largeaddressaware notifies the compiler application to support addresses larger than 2 GB
/Libpath allows the user to override the Environment library path
/Libpath: "E:/VC/lib"/libpath: "E:/dx/lib"
/Machine: Specify the Target Platform
'/Machine: {am33 | arm | EBC | IA64 | m32r | MIPS | mips16 | mipsfpu | mipsfp16|
Mipsr41xx | SH3 | sh3dsp | sh4 | sh5 | thumb | x86 | x64/* 8.0 */}
/Machine: x86
/Noentry create pure resource DLL
The/noentry option is required when a pure resource DLL is created.
/OPT control link optimization
If you generate components that only run on Windows NT or Windows 2000, use/OPT: nowin98.
/Subsystem: Specify the subsystem
{Console | efi_application | efi_boot_service_driver |
Efi_rom | efi_runtime_driver | native | POSIX | Windows |
WindowsCE} [, # [. #]
/Out specifies the output file name
/Out: hello.exe

Classic usage:
Link *. obj rc. res/libpath: "G:/Visual C ++/lib"/subsystem: Windows/machine: x86 kernel32.lib user32.lib gdi32.lib winspool. lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib UUID. lib odbc32.lib odbccp32.lib opengl32.lib

RC is resource Compilation
/L list the regions used by the Resource
0x804 China
0x409 USA
Usage:
RC/L 0x804 file. RC

Bytes ---------------------------------------------------------------------------------------------
The development of MFC is as follows:
Compile source code:
Cl *. CPP/Ox/OT/G7/D "Win32"/D "_ WINDOWS"/D "_ afxdll"/ESCs/MD/arch: sse2/W3/C
Resource Compilation:
RC/L 0x804 winmfc. RC
Link:
Link *. OBJ winmfc. Res/out: winmfc.exe/OPT: nowin98/subsystem: Windows/machine: x86

Bytes -----------------------------------------------------------------------------------------------

How to directly compile a program using cl.exe in the VC 6.0 directory

1. In "My Computer -- properties -- Advanced -- environment variables", add the following variables:

Include
D:/program files/Microsoft Visual Studio/vc98/include

Lib
D:/program files/Microsoft Visual Studio/vc98/lib

Path
X:/program files/Microsoft Visual Studio/common/msdev98/bin; X:/program files/Microsoft Visual Studio/vc98/bin
The xforwardeddisc is used by two drivers, because mspdb60.dll in the msdev98/bin directory is used by cl.exe.

If these variables already exist, add the preceding values to the values of the corresponding variables respectively. Note that the values are separated by semicolons before they are added.

2. Restart your computer

3. Open the command prompt and enter:
CL hello. c
Hello.exe and hello. OBJ will be generated in the directory after the carriage return.

 

From: http://blog.chinaunix.net/u/11315/showart_407032.html

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.