VSCode 将命令参数作为文字处理
VSCode deal the command parameter as literal
我想用 opencv.The 构建一个 Rasterizer 项目,下面的命令在 shell 中运行良好(省略了一些参数,例如 -static-libgcc
):
g++ *.cpp -g -o Rasterizer `pkg-config --libs opencv`
然而,当我想用 VSCode 做同样的事情时,它失败并抛出错误:
g++: error: `pkg-config --libs opencv`: No such file or directory
日志告诉我VSCode中执行的任务是(也省略了一些参数)
g++ *.cpp -g -o Rasterizer '`pkg-config --libs opencv`'
我觉得是参数的原因
`pkg-config --libs opencv`
被一对引号 '
包围,并被视为文字。我该如何解决这个问题?
完整的错误信息可以在这里看到:
> Executing task: g++ /home/cs18/GAMES101/pa1/*.cpp -fdiagnostics-color=always -g -o /home/cs18/GAMES101/pa1/build/main -static-libgcc -fexec-charset=GBK '`pkg-config --libs opencv`' <
g++: error: `pkg-config --libs opencv`: No such file or directory
The terminal process "/bin/bash '-c', 'g++ /home/cs18/GAMES101/pa1/*.cpp -fdiagnostics-color=always -g -o /home/cs18/GAMES101/pa1/build/main -static-libgcc -fexec-charset=GBK '`pkg-config --libs opencv`''" failed to launch (exit code: 1).
我的VSCode配置文件task.json
:
{
"tasks": [
{
"type": "shell",
"label": "C/C++: g++ build active file",
"command": "g++",
"args": [
"${fileDirname}/*.cpp",
"-fdiagnostics-color=always",
"-g",
"-o",
"${fileDirname}/build/${fileBasenameNoExtension}",
"-static-libgcc",
"-fexec-charset=GBK",
"`pkg-config --libs opencv`"
],
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "new"
},
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
让我们试试这个。
{
"tasks": [
{
"type": "shell",
"label": "C/C++: g++ build active file",
"command": "g++",
"args": [
"${fileDirname}/*.cpp",
"-fdiagnostics-color=always",
"-g",
"-o",
"${fileDirname}/build/${fileBasenameNoExtension}",
"-static-libgcc",
"-fexec-charset=GBK",
"${PKG_RET}"
],
"options": {
"env": {
"PKG_RET": "${input:pkg_ret}"
}
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "new"
},
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
},
"inputs": [
{
"id": "pkg_ret",
"type": "command",
"command": "shellCommand.execute",
"args": {
"command": "pkg-config --libs opencv"
}
}
]
参考:
我想用 opencv.The 构建一个 Rasterizer 项目,下面的命令在 shell 中运行良好(省略了一些参数,例如 -static-libgcc
):
g++ *.cpp -g -o Rasterizer `pkg-config --libs opencv`
然而,当我想用 VSCode 做同样的事情时,它失败并抛出错误:
g++: error: `pkg-config --libs opencv`: No such file or directory
日志告诉我VSCode中执行的任务是(也省略了一些参数)
g++ *.cpp -g -o Rasterizer '`pkg-config --libs opencv`'
我觉得是参数的原因
`pkg-config --libs opencv`
被一对引号 '
包围,并被视为文字。我该如何解决这个问题?
完整的错误信息可以在这里看到:
> Executing task: g++ /home/cs18/GAMES101/pa1/*.cpp -fdiagnostics-color=always -g -o /home/cs18/GAMES101/pa1/build/main -static-libgcc -fexec-charset=GBK '`pkg-config --libs opencv`' <
g++: error: `pkg-config --libs opencv`: No such file or directory
The terminal process "/bin/bash '-c', 'g++ /home/cs18/GAMES101/pa1/*.cpp -fdiagnostics-color=always -g -o /home/cs18/GAMES101/pa1/build/main -static-libgcc -fexec-charset=GBK '`pkg-config --libs opencv`''" failed to launch (exit code: 1).
我的VSCode配置文件task.json
:
{
"tasks": [
{
"type": "shell",
"label": "C/C++: g++ build active file",
"command": "g++",
"args": [
"${fileDirname}/*.cpp",
"-fdiagnostics-color=always",
"-g",
"-o",
"${fileDirname}/build/${fileBasenameNoExtension}",
"-static-libgcc",
"-fexec-charset=GBK",
"`pkg-config --libs opencv`"
],
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "new"
},
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
让我们试试这个。
{
"tasks": [
{
"type": "shell",
"label": "C/C++: g++ build active file",
"command": "g++",
"args": [
"${fileDirname}/*.cpp",
"-fdiagnostics-color=always",
"-g",
"-o",
"${fileDirname}/build/${fileBasenameNoExtension}",
"-static-libgcc",
"-fexec-charset=GBK",
"${PKG_RET}"
],
"options": {
"env": {
"PKG_RET": "${input:pkg_ret}"
}
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "new"
},
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
},
"inputs": [
{
"id": "pkg_ret",
"type": "command",
"command": "shellCommand.execute",
"args": {
"command": "pkg-config --libs opencv"
}
}
]
参考: