VSCode v1.19.4 cppbuild命令含引号致构建失败求助
解决VSCode C/C++扩展v1.19.4构建任务通配符失效问题
你的错误根源是把完整命令(含参数)直接塞到了command字段,VSCode会把整个字符串当作单个可执行文件路径去查找,而不是把/usr/bin/g++作为命令、后面的内容作为参数,所以才会报"not found"。
针对v1.19.4不再支持args通配符的问题,正确的解决方式是开启shell模式让系统shell解析通配符,同时保持command和args的正确拆分,配置示例如下:
{ "type": "cppbuild", "label": "C/C++: g++ build active files", "options": { "cwd": "${fileDirname}" }, "command": "/usr/bin/g++", "args": [ "-g", "-std=c++17", "-Wall", "-Wextra", "-pedantic-errors", "-Weffc++", "-Wno-unused-parameter", "-fsanitize=undefined,address", "${relativeFileDirname}/*.cpp", "-o", "${fileDirname}/${fileBasenameNoExtension}" ], "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true }, "detail": "compiler: /usr/bin/g++", "shell": true }
关键说明:
command字段仅保留编译器的绝对路径,不要添加任何参数- 所有编译参数(包括带通配符的源文件路径)拆分到
args数组中 - 添加
"shell": true,让系统shell负责解析args中的通配符(*.cpp),这样就能正确匹配目录下的所有cpp文件 - 必须保留
args字段,否则扩展会判定任务无效
内容的提问来源于stack exchange,提问作者DevWolf59
相关产品推荐
相关产品推荐

