因此,我使用Visual代码来构建和运行一个简单的C++程序。我使用tasks.json来处理编译:(基于这个:如何用VS代码和cl编译C++代码 )
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build Test",
"type": "shell",
"command": "cl",
"args": [
"/MDd",
"/W4",
"/EHsc",
"/ZI",
"/std:c++11",
"/Od",
"/Fe:${workspaceFolder}/Debug/test.exe",
"/Fd:${workspaceFolder}/Debug/",
"/Fo:${workspaceFolder}/Debug/",
"main.cpp"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "Build Release",
"type": "shell",
"command": "cl",
"args": [
"/MD",
"/W4",
"/EHsc",
"/std:c++11",
"/O2",
"/Fe:${workspaceFolder}/Release/test.exe",
"/Fd:${workspaceFolder}/Release/",
"/Fo:${workspaceFolder}/Release/",
"main.cpp"
]
}
]
}但是,当我试图构建时,我得到了以下输出:
Executing task: cl /MDd /W4 /EHsc /ZI /std:c++11 /Od "/Fe:G:\My Drive\Semester 3\CS 341\Project\Project 2/Debug/test.exe" "/Fd:G:\My Drive\Semester 3\CS 341\Project\Project 2/Debug/" "/Fo:G:\My Drive\Semester 3\CS 341\Project\Project 2/Debug/" main.cpp <
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.我要指出,我确实以下列方式更改了设置:
"terminal.integrated.shellArgs.windows": [
"/k",
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvars64.bat"
],
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe"我相信“C:\程序”就是从这里来的。我只想在Visual中构建和执行C++程序,所以希望得到一些帮助。
编辑:,因此我决定将C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Auxiliary\\Build添加到PATH变量中,然后将设置更改为:
"terminal.integrated.shellArgs.windows": [
"/k",
"vcvars64.bat",
],
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe"这导致错误变成:
> Executing task: cl /MDd /W4 /EHsc /ZI /std:c++11 /Od "/Fe:G:\My Drive\Semester 3\CS 341\Project\Project 2/Debug/test.exe" "/Fd:G:\My Drive\Semester 3\CS 341\Project\Project 2/Debug/" "/Fo:G:\My Drive\Semester 3\CS 341\Project\Project 2/Debug/" main.cpp <
[ERROR:vcvarsall.bat] Invalid argument found : /d
[ERROR:vcvarsall.bat] Invalid argument found : /c
[ERROR:vcvarsall.bat] Invalid argument found : cl
[ERROR:vcvarsall.bat] Invalid argument found : /MDd
[ERROR:vcvarsall.bat] Invalid argument found : /W4
[ERROR:vcvarsall.bat] Invalid argument found : /EHsc
[ERROR:vcvarsall.bat] Invalid argument found : /ZI
[ERROR:vcvarsall.bat] Invalid argument found : /std:c++11
[ERROR:vcvarsall.bat] Invalid argument found : /Od
The syntax of the command is incorrect.发布于 2019-03-02 15:59:56
空格和括号的问题可以通过转义字符来解决,在这种情况下,该字符是插入符号(^)。使用上述字符,settings.json中的相关行如下所示:
"terminal.integrated.shellArgs.windows": [
"/k",
"C:\\Program^ Files^ ^(x86^)\\Microsoft^ Visual^ Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvars64.bat"
],
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe"这种方法的问题与您在将vcvars64.bat路径添加到PATH变量时遇到的问题相同,即在执行任务时,Visual代码将从以/d和/c为前缀的tasks.json中将"command"和"args"的值附加到< Code >D14的值中。这将导致vcvars64.bat将上述值作为参数,而不是cmd.exe。标记为[ERROR:vcvarsall.bat]的错误出现是因为对参数的拒绝附加到了错误的位置。
可以通过为任务指定具有适当参数的shell来解决此问题,如下所示:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"options": {
"shell": {
"executable": "C:\\Windows\\System32\\cmd.exe",
"args": [
"/d", "/c",
"C:\\Program^ Files^ ^(x86^)\\Microsoft^ Visual^ Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvars64.bat",
"&&"
]
}
},
"tasks": [
{
"label": "Build Test",
"type": "shell",
"command": "cl",
"args": [
"/MDd",
"/W4",
"/EHsc",
"/ZI",
"/std:c++11",
"/Od",
"/Fe:${workspaceFolder}/Debug/test.exe",
"/Fd:${workspaceFolder}/Debug/",
"/Fo:${workspaceFolder}/Debug/",
"main.cpp"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "Build Release",
"type": "shell",
"command": "cl",
"args": [
"/MD",
"/W4",
"/EHsc",
"/std:c++11",
"/O2",
"/Fe:${workspaceFolder}/Release/test.exe",
"/Fd:${workspaceFolder}/Release/",
"/Fo:${workspaceFolder}/Release/",
"main.cpp"
]
}
]
}另一种方法是将"terminal.integrated.shellArgs.windows"保持为空,即不向settings.json中的cmd.exe传递任何参数,然后按如下方式更改tasks.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"options": {
"env": {
"build": "C:\\Program^ Files^ ^(x86^)\\Microsoft^ Visual^ Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvars64.bat && cl"
}
},
"tasks": [
{
"label": "Build Test",
"type": "shell",
"command": "%build%",
"args": [
"/MDd",
"/W4",
"/EHsc",
"/ZI",
"/std:c++11",
"/Od",
"/Fe:${workspaceFolder}/Debug/test.exe",
"/Fd:${workspaceFolder}/Debug/",
"/Fo:${workspaceFolder}/Debug/",
"main.cpp"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "Build Release",
"type": "shell",
"command": "%build%",
"args": [
"/MD",
"/W4",
"/EHsc",
"/std:c++11",
"/O2",
"/Fe:${workspaceFolder}/Release/test.exe",
"/Fd:${workspaceFolder}/Release/",
"/Fo:${workspaceFolder}/Release/",
"main.cpp"
]
}
]
}如果从Visual的Developer命令提示符启动Visual代码,则可以省略在每次生成之前调用vcvars64.bat的必要性。为了方便起见,可以使用以下tartget创建快捷方式:
cmd /d /c "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsDevCmd.bat" && start /b code这将使Developer命令提示符处于打开状态,可以按需关闭。
发布于 2021-06-22 06:41:23
文件夹名中的空格会中断提示,因此在settings.json文件中,请确保将路径"Program“更新为简单的"PROGRA~1”
当我改变的时候
"java.home": "C:\\Program Files\\JDK\\11" to
"java.home": "C:\\PROGRA~1\\JDK\\11"它开始工作了
https://stackoverflow.com/questions/52459661
复制相似问题