所以我正在使用Visual Studio Code来构建和运行一个简单的C ++程序。我使用task.json处理编译:(基于此:How to compile C++ code with VS Code and cl
{
// 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:\ Program”的来源。 我只想在Visual Studio中构建和执行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.
答案 0 :(得分:0)
在这种情况下,可以使用转义字符(即插入符号(^
)来解决空格和括号的问题。使用提到的字符,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 Studio Code将附加这些值执行任务时,从"command"
中以"args"
和tasks.json
为前缀的/d
和/c
中的"terminal.integrated.shellArgs.windows"
中的vcvars64.bat
。结果是cmd.exe
将获得提及的值作为参数,而不是[ERROR:vcvarsall.bat]
。出现带有{
// 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"
另一种方法是将cmd.exe
保留为空,即不要将任何参数传递给settings.json
中的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"
]
}
]
}
:< / p>
vcvars64.bat
如果从Visual Studio的开发人员命令提示符启动Visual Studio代码,则可以省略在每次构建之前调用cmd /d /c "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsDevCmd.bat" && start /b code
的必要性。为了方便起见,您可以使用以下控件创建快捷方式:
SELECT LISTAGG(output_author_name, ', ') WITHIN GROUP (ORDER BY
output_title_name),output_title_name
FROM tablename;
这将使开发人员命令提示符保持打开状态,可以根据需要将其关闭。
答案 1 :(得分:0)
文件夹名称中的空格会破坏提示,因此请确保在 settings.json 文件中将路径“Program Files”更新为简单的“PROGRA~1”
例如当我改变时
"java.home": "C:\\Program Files\\JDK\\11" to
"java.home": "C:\\PROGRA~1\\JDK\\11"
它开始工作了