Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/147.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何定义task.json来编译C/C++;在windows上使用cl.exe在vscode中编码?_C++_C_Windows_Visual Studio Code_Vscode Tasks - Fatal编程技术网

C++ 如何定义task.json来编译C/C++;在windows上使用cl.exe在vscode中编码?

C++ 如何定义task.json来编译C/C++;在windows上使用cl.exe在vscode中编码?,c++,c,windows,visual-studio-code,vscode-tasks,C++,C,Windows,Visual Studio Code,Vscode Tasks,我在64位Win 10上安装了微软Visual C++构建工具2015,可以使用C.exe编译和链接一个简单的命令提示窗口中的C/C++程序,通过以下步骤(一些指令): c只是一个简单的c源文件,用于打印“helloworld!”。我还尝试使用task.json在vs代码中直接编译和链接C/C++程序。这是我的task.json: { // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the document

我在64位Win 10上安装了微软Visual C++构建工具2015,可以使用C.exe编译和链接一个简单的命令提示窗口中的C/C++程序,通过以下步骤(一些指令):

c只是一个简单的c源文件,用于打印“helloworld!”。我还尝试使用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"
}
并且在路径中添加了
vsvarsall
cl
的路径。但它仍然不起作用(输出放在文章的末尾)。所以我的问题是:如何定义task.json,它可以首先运行
vcvvarsall amd64
来设置系统变量,然后执行
cl
命令来编译和链接程序

正如鲁道夫·邦杜利斯(Rudolfs Bundulis)所说,创建一个批处理文件并调用它,在其中完成所有需要做的事情

tasks.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"    
}
@echo off
call "E:\programs\VS2015\VC\vcvarsall.bat" x64      <----- update your path to vcvarsall.bat

..
cl %YourCompilerFlags% main.cpp %YourLinkerFlags%
..
在你的项目中有build.batgoodness

build.bat:

{
    // 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"    
}
@echo off
call "E:\programs\VS2015\VC\vcvarsall.bat" x64      <----- update your path to vcvarsall.bat

..
cl %YourCompilerFlags% main.cpp %YourLinkerFlags%
..
@echo关闭

调用“E:\programs\VS2015\VC\vcvarsall.bat”x64可能会提供一些关于它如何失败的输出?@rudolfsfbundulis:我已经在问题的末尾发布了输出。谢谢。好吧,我想我不能不安装VisualStudio代码并检查到底发生了什么。但是为什么你不能把你需要的东西放在一个
.bat
文件中,然后把
命令
参数指向它呢?这样就行了,而且您不必担心VSC如何处理该命令,因为您现在所做的事情似乎很奇怪—您将两个
cmd
操作连接在一起,并将一个文件作为参数传递给它。我建议创建一个批处理文件,并在
命令中设置它的路径。@RudolfsBundulis:好主意。我会试试。我遇到了与OP相同的问题。但是你如何为上面提到的vs代码创建引导程序?@MafiaSkafia很简单,引导程序只是一个批处理文件,其中包含复制的内容。该脚本是要启动的脚本,而不是vscode可执行文件。