Run CL command under Windows console

Source: Internet
Author: User
Tags lua

Premise: Make sure you have installed VC6 or VS series

We can then direct the command line to compile the C + + program

In the Windows operating system, open the command line, enter CL, if prompted

' CL ' is not an internal or external command, nor is it a running program or batch file.

If the VS is not installed or the environment variable is not set correctly, you can set it as follows:
1. Ensure that VS is installed and type set in the console
Check if there is an environment variable similar to the following format Vsxxcomntools

Vs90comntools=d:\program Files\Microsoft Visual Studio 9.0\common7\tools\

where xx is related to vs version:
a) VS2003 corresponding vs71comntools
b) VS2005 corresponding Vs80comntools
c) VS2008 corresponding Vs90comntools

If not, perform step 2, otherwise perform step 3

2. Create a new ring static variable in My Computer > Properties > Advanced > Environment Variables > System Variables
Variable name: vsxxcomntools
Variable Value: vs installation directory \common7\tools\
Repeat step 1

3. In the console, type

>call "%vs90comntools%" vsvars32.bat <== setting some environment variables for the CL runtime
>cl

Make sure there is no prompt error; Repeat step 1

Note: Setting an environment variable with set can only be guaranteed to take effect on this command line, and once the command-line window is closed, the setting is invalidated. To set up a different command-line window, use my Computer--environment variable to set

Introduction to CL Usage
CL has many options, please get the complete list via CL/?. Some of the most important options are listed here (the option prefix can be '-' or '/'), and there are examples.

No options
>CL foo.c bar.c <== compiles foo.obj,bar.obj and automatically calls the linker link to get Foo.EXE

/C compiles no links only
>CL/C foo.c bar.c <== compiles foo.obj,bar.obj, but does not invoke linker

/link <lib> Specify the library to link to
>cl/link kernel32.lib foo.c <== compiled foo.obj, and link kernel32.lib, get foo.exe

/I <dir> add directory to include search path

/d<name>{=|#}<text> Defining a preprocessor
>cl/d_crt_secure_no_deprecate/d_crt_nonstdc_no_deprecate <== definition of 2 preprocessor

CL Common options
/C compiles no links only
/o2 Set Speed optimization
/W3 Setting Warning Level 3

CL related explanations
More explanations about the CRT
How to suppress warning 4996

/d_crt_secure_no_deprecate Close warning:4996 (indicates strcpy unsafe warning, etc.)
/d_crt_nonstdc_no_deprecate non-standard C also off warning:4996
/MD more about the CRT explanation

Link Usage Profile
Link has a number of options, see http://msdn.microsoft.com/zh-tw/library/y0zzbyt4.aspx for the complete list, and here are just a few common options

[/debug] Generating debug information
Link/out:main.exe main.obj <== link main.obj and generate Main.exe

[/pdb:<target>] Generating debug symbol files
Link/debug/out:main.exe main.obj <== link main.obj and generate Main.exe with debug information

[/out:<target>] Specify output file
Link/debug/pdb:main.pdb/out:main.exe main.obj <== link main.obj and generate main.exe with debug information and debug symbol file main.pdb

[/subsystem:<target>] Specify subsystem http://msdn.microsoft.com/zh-cn/library/fcc1zstk.aspx
Link/subsystem:windows/out:main.exe main.obj kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib Shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib <== compiled Windows program, the entry function is automatically set to WinMain, where kernel32.lib ,..., Odbccp32.lib such as Lib that must be linked for Windows programs

[/libpath:<dir>] Add the directory to the Lib search path. If there are multiple paths, write multiple/libpath
Link/libpath:.. /common/out:main.exe main.obj lua.lib <== Link: The Lua.lib in/common

It is worth noting that:
If both main and WinMain are provided, then the/SUBSYSTEM must be specified manually
If only main is supplied, the linker automatically assigns/subsystem:console

Application examples
Usually we use CL and link separately: Here's a script to compile Lua

CL/MD/O2/W3/C/d_crt_secure_no_deprecate/d_crt_nonstdc_no_deprecate/dlua_build_as_dll l*.c
Del lua.obj luac.obj <== above CL compiles all the l*.c, while Lua.obj and luac.obj are not required link, so delete the
Link/dll/out:lua51.dll L*.obj

Transferred from: http://blog.csdn.net/daisy19900111/article/details/8035131

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.