当只有源文件hello.c 的时候,没有工程,没法用IDE(集成开发环境),前提是电脑要装一个IDE,有cl.exehtml
使用时要配好环境变量,cmd要定位文件目录下,用cl /c hello.c 只编译,不连接 生成hello.obj文件c++
而后用link hello.obj 命令,生成hello.exe文件。 cl hello.cgit
首先写一个无缺的C语言程序,能够运行的通,天然是简单就好,下面给出一个简单的示例供参考:windows
#include<stdio.h>浏览器
int main(void)
{
char *string = "Hello World!";
printf("%s\n",string);
return 0;
}框架
使用lc命令进行编译,可是却给出下面的提示(cl.exe是vc++6.0中的一个命令,因此要用的话,须要先安装vc++6.0):异步
其实上面之因此会出现这样的现象是觉得,cl.exe命令虽然存在,可是你尚未配置环境变量,因此并非在什么地方均可以用,因此会在刚才给出那样的提 示,因而咱们须要去配置环境变量(计算机(个人电脑)->属性->高级系统配置->高级->环境变量->系统变量 ->path),在path中最后加入“C:\Program Files\Microsoft Visual Studio\VC98\Bin”(vc++6.0的bin目录),而后从新运行,会给出“没法启动此程序,由于计算机中丢失mspdb60.dll。尝 试从新安装该程序以解决此问题。”也就说少了一个动态连接库文件,这时你只要将它须要的这个.dll文件拷贝到刚才那个bin目录下就能够了。(mspdb60.dll下载地址)async
上面的工做都作完了之后,就开始正式编译运行这个程序,仍是使用上面给出的cl demo.c,却给出以下的提示,貌似是真的仍是不行哦~~~当时就小小的郁闷了一把,可是一看错误,原来提示是没有给出头文件<stdio.h>的路径,就是说它找不到头文件,因而到网上搜索了一下,结果发现原来是能够解决的。函数
因而尝试了下面的一种方式,就是另外写一个.bat文件用来专门写dos命令行,从而能够顺利的加入头文件和lib文件,其中的代码以下:优化
set INCLUDE=C:\Program Files\Microsoft Visual Studio\VC98\Include
//设置头文件路径,从而能够找到头文件
set LIB=C:\Program Files\Microsoft Visual Studio\VC98\Lib
//设置lib文件路径,从而能够找到lib文件
cl D:\demo1.c
//编译D:\demo1.c源文件
cmd /k echo
//这条命令行,是我找了很久才找到,就是要停留在运行完的程序的地方,这样咱们才能够继续操做或是在不彻底正确的时候能够查看一下错误在什么地方,经过这条命令就能够中止在编译链接过的dos窗口的地方。
编译连接都完成了,而后能够经过输入命令*.exe方法直接能够运行查看结果,到此整个编译连接和运行过程就完成了,还有更多不太了解的地方,你们能够查看csdn上的不少的东东。
本人也是现学现卖,之前学的时候没有注意到这些,如今有一个朋友问起才学了一下,但愿能够帮到你们。
cl命令:
-优化-
|
||
/O1 | 最小化空间 | minimize space |
/Op[-] | 改善浮点数一致性 | improve floating-pt consistency |
/O2 | 最大化速度 | maximize speed |
/Os | 优选代码空间 | favor code space |
/Oa | 假设没有别名 | assume no aliasing |
/Ot | 优选代码速度 | favor code speed |
/Ob | 内联展开(默认 n=0) | inline expansion (default n=0) |
/Ow | 假设交叉函数别名 | assume cross-function aliasing |
/Od | 禁用优化(默认值) | disable optimizations (default) |
/Ox | 最大化选项。(/Ogityb2 /Gs) | maximum opts. (/Ogityb1 /Gs) |
/Og | 启用全局优化 | enable global optimization |
/Oy[-] | 启用框架指针省略 | enable frame pointer omission |
/Oi | 启用内建函数 | enable intrinsic functions |
-代码生成-
|
||
/G3 | 为 80386 进行优化 | optimize for 80386 |
/G4 | 为 80486 进行优化 | optimize for 80486 |
/GR[-] | 启用 C++ RTTI | enable C++ RTTI |
/G5 | 为 Pentium 进行优化 | optimize for Pentium |
/G6 | 为 Pentium Pro 进行优化 | optimize for Pentium Pro |
/GX[-] | 启用 C++ 异常处理(与 /EHsc 相同) | enable C++ EH (same as /EHsc) |
/EHs | 启用同步 C++ 异常处理 | enable synchronous C++ EH |
/GD | 为 Windows DLL 进行优化 | optimize for Windows DLL |
/GB | 为混合模型进行优化(默认) | optimize for blended model (default) |
/EHa | 启用异步 C++ 异常处理 | enable asynchronous C++ EH |
/Gd | __cdecl 调用约定 | __cdecl calling convention |
/EHc | extern“C”默认为 nothrow | extern "C" defaults to nothrow |
/Gr | __fastcall 调用约定 | __fastcall calling convention |
/Gi[-] | 启用增量编译 | enable incremental compilation |
/Gz | __stdcall 调用约定 | __stdcall calling convention |
/Gm[-] | 启用最小从新生成 | enable minimal rebuild |
/GA | 为 Windows 应用程序进行优化 | optimize for Windows Application |
/Gf | 启用字符串池 | enable string pooling |
/QIfdiv[-] | 启用 Pentium FDIV 修复 | enable Pentium FDIV fix |
/GF | 启用只读字符串池 | enable read-only string pooling |
/QI0f[-] | 启用 Pentium 0x0f 修复 | enable Pentium 0x0f fix |
/Gy | 分隔连接器函数 | separate functions for linker |
/GZ | 启用运行时调试检查 | enable runtime debug checks |
/Gh | 启用钩子函数调用 | enable hook function call |
/Ge | 对全部函数强制堆栈检查 | force stack checking for all funcs |
/Gs[num] | 禁用堆栈检查调用 | disable stack checking calls |
-输出文件-
|
||
/Fa[file] | 命名程序集列表文件 | name assembly listing file |
/Fo | 命名对象文件 | name object file |
/FA[sc] | 配置程序集列表 | configure assembly listing |
/Fp | 命名预编译头文件 | name precompiled header file |
/Fd[file] | 命名 .PDB 文件 | name .PDB file |
/Fr[file] | 命名源浏览器文件 | name source browser file |
/Fe | 命名可执行文件 | name executable file |
/FR[file] | 命名扩展 .SBR 文件 | name extended .SBR file |
/Fm[file] | 命名映射文件 | name map file |
-预处理器-
|
||
/FI | 命名强制包含文件 | name forced include file |
/C | 不吸收注释 | don't strip comments |
/U | 移除预约义宏 | remove predefined macro |
/D{=|#} | 定义宏 | define macro |
/u | 移除全部预约义宏 | remove all predefined macros |
/E | 将预处理定向到标准输出 | preprocess to stdout |
/I
|
添加到包含文件的搜索路径 | add to include search path |
/EP | 将预处理定向到标准输出,不要带行号 | preprocess to stdout, no #line |
/X | 忽略“标准位置” | ignore "standard places" |
/P | 预处理到文件 | preprocess to file |
-语言-
|
||
/Zi | 启用调试信息 | enable debugging information |
/Zl | 忽略 .OBJ 中的默认库名 | omit default library name in .OBJ |
/ZI | 启用调试信息的“编辑并继续”功能 | enable Edit and Continue debug info |
/Zg | 生成函数原型 | generate function prototypes |
/Z7 | 启用旧式调试信息 | enable old-style debug info |
/Zs | 只进行语法检查 | syntax check only |
/Zd | 仅要行号调试信息 | line number debugging info only |
/vd{0|1} | 禁用/启用 vtordisp | disable/enable vtordisp |
/Zp[n] | 在 n 字节边界上包装结构 | pack structs on n-byte boundary |
/vm | 指向成员的指针类型 | type of pointers to members |
/Za | 禁用扩展(暗指 /Op) | disable extensions (implies /Op) |
/noBool | 禁用“bool”关键字 | disable "bool" keyword |
/Ze | 启用扩展(默认) | enable extensions (default) |
- 杂项 -
|
||
/?, /help | 打印此帮助消息 | print this help message |
/c | 只编译,不连接 | compile only, no link |
/W | 设置警告等级(默认 n=1) | set warning level (default n=1) |
/H | 最大化外部名称长度 | max external name length |
/J | 默认 char 类型是 unsigned | default char type is unsigned |
/nologo | 取消显示版权消息 | suppress copyright message |
/WX | 将警告视为错误 | treat warnings as errors |
/Tc | 将文件编译为 .c | compile file as .c |
/Yc[file] | 建立 .PCH 文件 | create .PCH file |
/Tp | 将文件编译为 .cpp | compile file as .cpp |
/Yd | 将调试信息放在每一个 .OBJ 中 | put debug info in every .OBJ |
/TC | 将全部文件编译为 .c | compile all files as .c |
/TP | 将全部文件编译为 .cpp | compile all files as .cpp |
/Yu[file] | 使用 .PCH 文件 | use .PCH file |
/V | 设置版本字符串 | set version string |
/YX[file] | 自动的 .PCH 文件 | automatic .PCH |
/w | 禁用全部警告 | disable all warnings |
/Zm | 最大内存分配(默认为 %) | max memory alloc (% of default) |
-连接-
|
||
/MD | 与 MSVCRT.LIB 连接 | link with MSVCRT.LIB |
/MDd | 与 MSVCRTD.LIB 调试库连接 | link with MSVCRTD.LIB debug lib |
/ML | 与 LIBC.LIB 连接 | link with LIBC.LIB |
/MLd | 与 LIBCD.LIB 调试库连接 | link with LIBCD.LIB debug lib |
/MT | 与 LIBCMT.LIB 连接 | link with LIBCMT.LIB |
/MTd | 与 LIBCMTD.LIB 调试库连接 | link with LIBCMTD.LIB debug lib |
/LD | 建立 .DLL | Create .DLL |
/F | 设置堆栈大小 | set stack size |
/LDd | 建立 .DLL 调试库 | Create .DLL debug libary |
/link | [连接器选项和库] | [linker options and libraries] |