Windows中cl命令编译运行C++
author@jason_ql(lql0716)
http://blog.csdn.net/lql0716
在dos命令窗口,利用cl命令编译运行C++;
设置步骤:
1、正确安装Visual Studio 2013
我的安装路径是:
“C:\Program Files (x86)\Microsoft Visual Studio 12.0\”2、设置环境变量
- PATH 中添加
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin - 添加环境变量 INCLUDE:
INCLUDE = C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include - 添加环境变量 LIB
LIB = C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib
- PATH 中添加
3、测试cl命令
- 在dos命令窗口输入命令:
cl
显示如下结果,则为配置成功
- 在dos命令窗口输入命令:
4、用cl命令编译运行C++程序
//hw.cpp
#include <iostream>
using namespace std;
int main(){
cout << "print ! ! ! ! ! ! " << endl;
system("pause"); //改命令可以使得窗口
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 编译print.cpp:
cl -GX hw.cpp
显示如下结果,则为配置成功
如果提示
LINK:fatal error LNK1104: 无法打开文件 “uuid.lib”
,则将路径C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib
下的uuid.lib
复制到C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib
;同理,出现其他类似形式错误提示LINK:fatal error LNK*: 无法打开文件“*.lib”
,也是同样的操作
- 5、多个cpp文件一起编译运行
如:
test.h
,test.cpp
,hw.cpp
,print文件调用了test.h
命令形式:cl hw.cpp test.cpp
![]()
test.h
//test.h
#ifndef TEST_H
#define TEST_H
void get();
#endif
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
test.cpp
//test.cpp
#include "test.h"
#include <iostream>
using namespace std;
void get(){
cout << "Very Good, get it.\n" << endl;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
hw.cpp
//hw.cpp
#include <iostream>
#include "test.h"
using namespace std;
int main(){
cout << "printing ! ! ! \n" << endl;
get();
system("pause");
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11