Yul*_* Ao 5 c c++ windows visual-studio-code vscode-tasks
我已经在我的 64 位 win10 上安装了 Microsoft Visual C++ Build Tools 2015,并且可以使用 cl.exe 通过以下步骤在普通命令提示符窗口中编译和链接 C/C++ 程序(一些说明来自设置路径和环境命令行构建的变量):
1. cd "\Program Files (x86)\Microsoft Visual Studio 14.0\VC"
2. vcvarsall amd64
3. cl helloworld.c
Run Code Online (Sandbox Code Playgroud)
helloworld.c 只是一个简单的 C 源文件,用于打印“Hello world!”。我也尝试配置task.json,直接在vs代码中编译链接C/C++程序。这是我的 task.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "vcvarsall amd64 && cl",
"isShellCommand": true,
"args": ["${file}"],
"showOutput": "always"
}
Run Code Online (Sandbox Code Playgroud)
和路径vsvarsall,并cl已在PATH被添加。但它仍然不起作用(输出放在帖子的末尾)。所以我的问题是:如何定义 task.json ,它可以先运行vcvarsall amd64以设置系统变量,然后执行cl命令来编译和链接程序。
正如Rudolfs Bundulis所说,创建一个批处理文件并调用它,在其中执行您需要执行的所有操作。
任务.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "build.bat",
"isShellCommand": true,
"args": [],
"showOutput": "always"
}
Run Code Online (Sandbox Code Playgroud)
并且在您的项目中拥有build.bat 的优点。
构建.bat:
@echo off
call "E:\programs\VS2015\VC\vcvarsall.bat" x64 <----- update your path to vcvarsall.bat
..
cl %YourCompilerFlags% main.cpp %YourLinkerFlags%
..
Run Code Online (Sandbox Code Playgroud)
我要提到的是,您希望有另一个 Visual Studio Code Bootstraper 批处理来设置 vcvars 环境,然后启动编辑器,这样您就不必为每个构建设置 vcvars。就像这样:
@echo off
call "E:\programs\VS2015\VC\vcvarsall.bat" x64 <----- update your path to vcvarsall.bat
code
Run Code Online (Sandbox Code Playgroud)
这样你就可以省略vcvarsall.bat每次编译代码时的设置。最小重建标志也会对您有很大帮助,因此您只需编译更改的文件。
| 归档时间: |
|
| 查看次数: |
7295 次 |
| 最近记录: |