Microsoft C/C ++/C # compiler command line mode setting and usage

Source: Internet
Author: User
Tags mscorlib microsoft c

Microsoft C/C ++/C # compiler command line mode setting and usage

Compared with compiling in IDE, the command line mode is faster, and some additional information generated by IDE can be avoided.
Interference. This article describes how to set and use the command line mode of the Microsoft C/C ++/C # compiler. The operating system is Windows
2000.

1. Microsoft C/C ++ compiler Command Line Mode settings

Method 1

1. Compile a batch processing file by referring to the following content (according to your system situation,
Assume that the name is vs. bat.

@ Echo off

Set Path = C:/winnt/system32; D:/Vs. Net/vc7/bin; D:/Vs. Net/common7/ide

Set include = D:/Vs. Net/vc7/include

Set Lib = D:/Vs. Net/vc7/lib

Note:

A. The above environment variable strings are case-insensitive, but spaces should be avoided between characters.

B. C:/winnt/system32 is added to facilitate the use of extended commands such as help, and
This topic is not directly related.

2. Open a "command prompt" window and execute the following command:

C:/> Start C:/vc7.bat (modify the file path accordingly)

A new "command prompt" window is created. In this window, you can compile the C ++ program. With
Body usage, which will be discussed later.

The disadvantage of this setting method is that it can only be compiled in the "command prompt" window created in step 2. Once
Close this window to re-Execute step 2.

Method 2

1. on the desktop "my computer" icon, right-click and execute the "properties" menu command, or,
Follow the steps "start"-"set"-"Control Panel" and double-click the "System" icon.
Sex dialog box. Select the "advanced" Page and click "environment variables". The environment change shown in Figure 1 is displayed.
Volume settings window. (Note: any user can add/delete/modify user environment variables, but only the administrator can add/delete
/Change system environment variables. USER environment variables can be different for each user on a specific computer)

Figure 1

2. You can set it to a user environment variable or a system environment variable. Refer to the following content and
See figure 2. (Make adjustments based on your system)

Path = C:/winnt/system32; D:/Vs. Net/vc7/bin; D:/Vs. Net/common7/ide

Include = D:/Vs. Net/vc7/include

Lib = D:/Vs. Net/vc7/lib

Figure 2

Different from method 1, this method can be used once it is set up. No need to restart computing
Now, open a "command prompt" window and execute the CL command.

NOTE: If your operating system is Windows 95/98, You can edit autoexec. BAT as described above.
File.

Ii. Visual C #. Net compiler command line mode setting

C # The method for setting the command line mode of the compiler is similar. You only need to add C:/W to the path.
Innt/Microsoft. NET/framework/v1.0.3705. Currently, PATH environment variable settings on my machine
As follows:


Path = C:/winnt/system32; D:/Vs. Net/vc7/bin; D:/Vs. Net/common7/ide; C:/winnt/micro
Soft. Net/framework/v1.0.3705; D:/Vs. Net/frameworksdk/bin; D:/bcc55/bin; E:/CMDL
E/ora81/bin

Iii. Microsoft C/C ++ compiler command line mode usage

Microsoft C/C ++ compiler has a large number of compilation options. In the "command prompt" window, type Cl /? To view the complete Column
Table (see appendix 1 ). For example,/GX enables the C ++ Exception Handling Mechanism,/GR enables C ++ rtti, and so on. Not here
We plan to discuss in detail the usage of these compilation options.

The following is an example file in my test directory F:/vstest:

// 1.cpp

# Include <iostream>

Using namespace STD;

Void main ()

{

Cout <"Hello Royal" <Endl;

}

Now you can go to this directory and execute the following compilation command:

F:/vstest> Cl/GX 1.cpp

Run the program to generate the following output:

Hello Royal

It is also easy to compile multiple files. See the following example:

// 2.cpp

# Include <iostream>

# Include "3.cpp"

Using namespace STD;

Void main ()

{

Ctest CT ("Hello www.royaloo.com ");

Cout <CT. Str <Endl;

}


// 3.cpp

# Include <string>

Using namespace STD;

Class ctest

{

Public:

Ctest (string strvalue): STR (strvalue ){}

String STR;

};

Run the following compilation command:

F:/vstest> Cl/GX 2.cpp 3.cpp

You can also compile the file to specify the name of the generated EXE:

F:/vstest> Cl/GX/fehello.exe 2.cpp 3.cpp (generate hello.exe)

Run the program and the output result is as follows:

Hello www.royaloo.com

Iv. Visual C #. Net compiler command line mode usage


# Is specified.

# Reference the common framework Libraries
/R: accessibility. dll
/R: Microsoft. VSA. dll
/R: system. configuration. Install. dll
/R: system. Data. dll
/R: system. Design. dll
/R: system. directoryservices. dll
/R: system. dll
/R: system. Drawing. Design. dll
/R: system. Drawing. dll
/R: system. javasiseservices. dll
/R: system. Management. dll
/R: system. messaging. dll
/R: system. runtime. remoting. dll
/R: system. runtime. serialization. formatters. Soap. dll
/R: system. Security. dll
/R: system. serviceprocess. dll
/R: system. Web. dll
/R: system. Web. regularexpressions. dll
/R: system. Web. Services. dll
/R: system. Windows. Forms. dll
/R: system. xml. dll


.

The following is an example file in my test directory F:/vstest:

// 4.cs

Using system;

Namespace _ 4

{

Class class1

{

[Stathread]

Static void main (string [] ARGs)

{

Console. writeline ("Hello Royal ");

}

}

}

Run the following compilation command:


Run the program, that is, output:

Hello Royal

The following is an example of compiling multiple files:

// 5.cs

Using system;

Using _ 6;

Namespace _ 5

{

Class class5

{

[Stathread]

Static void main (string [] ARGs)

{

Class6 C6 = new class6 ("Hello www.royaloo.com ");

Console. writeline (c6.str );

}

}

}

// 6.cs

Using system;

Namespace _ 6

{

Class class6

{

Public class6 (string strvalue) {STR = strvalue ;}

Public String STR;

}

}

Run the following compilation command:


When you run the program, the following words are output:

Hello www.royaloo.com

Appendix 1 (for more details, refer to msdn)

Microsoft C/C ++ compiler options

-Optimization-

/O1
Minimize Space

/OP [-]
Improve floating point consistency

/O2
Maximum speed

/OS
Preferred code space

/OA
Assume there is no alias

/OT
Code Speed Optimization

/Ob <n>
Inline expansion (n = 0 by default)

/Ow
Assume that the cross-function alias

/OD
Disable optimization (default)

/Ox
Maximize options. (/Ogityb2/GS)

/Og
Enable Global Optimization

/Oy [-]
Enable frame pointer omitted

/OI
Enable internal functions

-Code Generation-

/G3
Optimized for 80386

/GH
Enable _ pexit function call

/G4
Optimized for 80486

/GR [-]
Enable C ++ rtti

/G5
Optimize Pentium

/GX [-]
Enable C ++ EH (same as/ESCS)

/G6
Optimization for ppro, p-II, P-III

/EHS
Enable C ++ EH (no seh exception)

/GB
Optimize the hybrid model (default)

/EHA
Enable C ++ EH (W/seh exception)

/GD
_ Cdecl call conventions

/EHC
The default external "C" is nothrow.

/GR
_ Fastcall call Convention

/GT
Generate fiber-safe TLS access

/GZ
_ Stdcall call Convention

/GM [-]
Enable minimum regenerate

/GA
Optimize Windows Applications

/GL [-]
Enable link generation

/GF
Enable string pool

/Qifdiv [-]
Enable Pentium fdiv repair

/GF
Enable Read-Only string pool

/Qi0f [-]
Enable Pentium 0x0f repair

/Gy
Separate linker Functions

/Qifist [-]
Use fist instead of ftol ()

/GZ
Enable stack check (/RTCs)

/Rtc1
Enable quick check (/rtcsu)

/Ge
Force stack check for all functions

/RTCC
Convert to a smaller type check

/GS [num]
Control Stack check call

/RTCs
Stack frame runtime check

/GS
Enable Security Check

/Rtcu
Uninitialized local usage check

/GH
Enable _ penter function call

/CLR [: noassembly]
Compile noassembly for the public language runtime-No assembly is generated

-Output file-

/FA
Named assembly list file

/FO <File>
Named object file

/Fa [SC]
Configure the Assembly List

/FP <File>
Naming precompiled header files

/FD
Name the. PDB File

/FR
Name the source browser File

/Fe <File>
Naming executable files

/FR
Name extension. SBR File

/FM
Name ing File

-Pre-processor-

/AI <dir>
Add to Assembly search path

/FX
Merge the inserted code into a file

/Fu <File>
Force use of assembly/Module

/FI <File>
Mandatory File Inclusion

/C
Do not extract comments

/U <Name>
Remove a predefined macro

/D <name >{=|#}< text>
Definition macro

/U
Remove all predefined macros

/E
Preprocessing to stdout

/I <dir>
Add to include search path

/EP
Pre-process to stdout, no # Line

/X
Ignore "standard location"

/P
Preprocessing to files

-Language-

/Zi
Enable debugging information

/ZL
Ignore the default database name in. OBJ

/Zi
Enable "edit and continue" debugging information

/ZG
Generate function prototype

/Z7
Enable legacy debugging information

/Zs
Only perform syntax check

/ZD
Only line number debugging information is available.

/VD {0 | 1}
Disable/enable vtordisp

/ZP [N]
Wrap the structure on the N-byte Boundary

/Vm <x>
Pointer type to a member

/Za
Disable extension (/OP)

/Nobool
Disable the "bool" keyword

/Ze
Enable extension (default)

/ZC: arg1 [, arg2]
C ++ language consistency. The parameter here can be: forscope-enforce the use of standard C ++ for range rules;
Wchar_t-wchar_t is the native type, not typedef

-Miscellaneous-

@ <File>
Option response File

/WO <n>
Issue a warning n

/?, /Help
Print this help message

/W <L> <n>
Set Warning Level 1-4 for N

/C
Compile only, not link

/W <n>
Set the warning level (n = 1 by default)

/H <num>
Maximum length of external name

/Wall
Enable all warnings

/J
The default char type is unsigned.

/Wp64
Enable 64-bit port locating warning

/Nologo
Cancel copyright display

/Wx
Treat warnings as errors

/Showincludes
Show include file name

/WL
Enable single row Diagnosis

/Tc <Source File>
Compile the file into. c

/YC
Create a. PCH File

/TP <Source File>
Compile the file as. cpp

/Yd
Place debugging information in each. OBJ

/TC
Compile all files into. c

/YL [sym]
Insert. PCH reference for the debugging Library

/TP
Compile all files into. cpp

/Yu
Use the. PCH File

/V <string>
Set version string

/Yx
Automatic. PCH

/W
Disable all warnings

/Y-
Disable all PCH options

/WD <n>
Disable warning n

/ZM <n>
Maximum memory allocation (% by default)

/We <n>
Regard warning N as an error

-Link-

/MD
Link to msvcrt. Lib

/MDD
Link to msvcrtd. Lib debugging Library

/Ml
Link to libc. Lib

/MLD
Link to the libcd. Lib debugging Library

/Mt
Link to libcmt. Lib

/MTD
Link to the libcmtd. Lib debugging Library

/LD
Create. dll

/F <num>
Set stack size

/LDD
Create a. dll debugging Library

/Link
[Linker Options and libraries]

Appendix 2 (for more details, refer to msdn)

Visual C #. Net compiler options

-Output file-

/Out: <File>
Output file name (default value: base name of the file containing the main class or the first file)

/Target: exe
Generate the console executable file (default) (Abbreviation:/T: exe)

/Target: winexe
Generate a Windows Executable File (Abbreviation:/T: winexe)

/Target: Library
Generate a library (Abbreviation:/T: Library)

/Target: Module
Generate a module that can be added to another assembly (Abbreviation:/T: module)

/Define: <symbol list>
Define Conditional compilation symbols (Abbreviation:/D)

/DOC: <File>
XML document file to be generated

-Input file-

/Recurse: <wildcard>
According to the wildcard specification, including all files in the current directory and subdirectory

/Reference: <file list>
Reference metadata from the specified Assembly file (Abbreviation:/R)

/Addmodule: <file list>
Link the specified module to this Assembly

-Resource-

/Win32res: <File>
Specify the Win32 resource file (. Res)

/Win32icon: <File>
Use this icon to output

/Resource: <Resource Information>
Embed the specified resource (Abbreviation:/RES)

/Linkresource: <Resource Information>
Link the specified resource to this Assembly (Abbreviation:/linkres)

-Code Generation-

/Debug [+ |-]
Issue debugging information

/Debug: {full | pdbonly}
Specify the debugging type ("full" is the default type. You can attach the debugging program to a running program)

/Optimize [+ |-]
Enable optimization (Abbreviation:/O)

/Incremental [+ |-]
Enable incremental compilation (Abbreviation:/incr)

-Errors and warnings-

/Warnaserror [+ |-]
Treat warnings as errors

/Warn: <n>
Set the warning level (0-4) (Abbreviation:/W)

/Nowarn: <warning list>
Disable specific warning messages

-Language-

/Checked [+ |-]
Generate overflow check

/Unsafe [+ |-]
Allow "insecure" code

-Miscellaneous-

@ <File>
Read the response file for more options

/Help
Display this usage information (Abbreviation :/?)

/Nologo
Cancel compiler copyright information

/Noconfig

-Advanced-

/Baseaddress: <address>
Base Address of the database to be generated

/Bugreport: <File>
Create an "Error Report" File

/CodePage: <n>
Specifies the code page to be used to open the source file

/Utf8output
Output compiler message for UTF-8 Encoding

/Main: <type>
Specifies the type of the entry point (ignore all other possible entry points) (Abbreviation:/m)

/Fullpaths
The compiler generates a fully qualified path

/Filealign: <n>
Specifies the alignment for the output file section.

/Nostdlib [+ |-]
Do not reference standard library (mscorlib. dll)

/Lib: <file list>
Specify the additional directory to be referenced in the search

 

Related Article

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.