命令行下使用CL.exe编译多cpp文件工程

来源:互联网 发布:公司网络服务器搭建 编辑:程序博客网 时间:2024/06/04 18:40

一、CL.exe是控制 Microsoft C 和 C++ 编译器与链接器的 32 位工具。编译器产生通用对象文件格式 (COFF) 对象 (.obj) 文件。链接器产生可执行文件 (.exe) 或动态链接库文件 (DLL)。

用法如下,注意,所有编译器选项都区分大小写。

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

cl /?可以查看具体参数,自己去看吧,我就不列出来了

精典用法:

cl *.cpp /G7 /MD /Ox /Ot /W3 /c /EHsc /I"G:\Visual C++\VC98\PlatformSDK\Include"

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

二、Link.exe 是将通用对象文件格式 (COFF) 对象文件和库链接起来以创建 32 位可执行 (.exe) 文件或动态链接库 (DLL) 的 32 位工具。

同理LINK  /?查看具体参数

精典用法:

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.exe是资源编译,同样rc /?查看具体参数

/l 列出资源用的区域性 

0x804 中国

0x409 美国 

用法:

rc /l 0x804 file.rc

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

四、MFC下开发如下:

以下均为vc6.0编译Release时使用的标准用法,others替换为你自己的cpp名即可,对预编译头文件stdafx.cpp的编译稍有不同

编译源代码:

cl.exe stdafx.cpp /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /Fp"Release/Test.pch" /Yc"stdafx.h" /Fo"Release/" /Fd"Release/" /FD /c

cl.exe others.cpp  /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /Fp"Release/Test.pch" /Yu"stdafx.h" /Fo"Release/" /Fd"Release/" /FD /c

资源编译 :

rc.exe /l 0x804 "/foRelease/Test.res" /d "NDEBUG" /d "_AFXDLL" "F:\ReleasePi\Test\Test.rc"

链接 :

link.exe /nologo /subsystem:windows /incremental:no "/pdb:Release/Test.pdb" /machine:I386 "/out:Release/Test.exe" .\Release\StdAfx.obj .\Release\others.obj .\Release\Test.res

0 0