我是靠谱客的博主 美好雨,这篇文章主要介绍Windows中cl命令编译运行C++,现在分享给大家,希望可以做个参考。

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.0VCbin
    • 添加环境变量 INCLUDE:
      INCLUDE = C:Program Files (x86)Microsoft Visual Studio 12.0VCinclude
    • 添加环境变量 LIB
      LIB = C:Program Files (x86)Microsoft Visual Studio 12.0VClib
  • 3、测试cl命令

    • 在dos命令窗口输入命令:cl
      显示如下结果,则为配置成功
      此处输入图片的描述
  • 4、用cl命令编译运行C++程序

复制代码
1
2
3
4
5
6
7
8
9
//hw.cpp #include <iostream> using namespace std; int main(){ cout << "print ! ! ! ! ! ! " << endl; system("pause"); //改命令可以使得窗口 }
  • 编译print.cpp:cl -GX hw.cpp
    显示如下结果,则为配置成功
    此处输入图片的描述

如果提示LINK:fatal error LNK1104: 无法打开文件 “uuid.lib”,则将路径C:Program Files (x86)Microsoft SDKsWindowsv7.1ALib下的uuid.lib复制到C:Program Files (x86)Microsoft Visual Studio 12.0VClib;同理,出现其他类似形式错误提示LINK:fatal error LNK*: 无法打开文件“*.lib”,也是同样的操作
此处输入图片的描述


  • 5、多个cpp文件一起编译运行

如:test.h, test.cpp, hw.cpp,print文件调用了test.h
命令形式:cl hw.cpp test.cpp
此处输入图片的描述
test.h

复制代码
1
2
3
4
5
6
7
8
9
//test.h #ifndef TEST_H #define TEST_H void get(); #endif

test.cpp

复制代码
1
2
3
4
5
6
7
8
9
//test.cpp #include "test.h" #include <iostream> using namespace std; void get(){ cout << "Very Good, get it.n" << endl; }

hw.cpp

复制代码
1
2
3
4
5
6
7
8
9
10
11
//hw.cpp #include <iostream> #include "test.h" using namespace std; int main(){ cout << "printing ! ! ! n" << endl; get(); system("pause"); }

参考:通过命令行使用cl.exe编译器

最后

以上就是美好雨最近收集整理的关于Windows中cl命令编译运行C++的全部内容,更多相关Windows中cl命令编译运行C++内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(87)

评论列表共有 0 条评论

立即
投稿
返回
顶部