完整命令是用pkg-config输出opencv4的包含和链接信息,并且作为g++的参数进行编译:
pkg-config --cflags --libs --static opencv4 | xargs g++ -g example.cpp -o example
方法:在tasks.json中删掉掉原本的args项,并将完整命令直接赋值给command项,最终完整的tasks.json文件为:
{
// 有关 tasks.json 格式的文档,请参见
// https://go.microsoft.com/fwlink/?LinkId=733558
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++ build active file",
"command": "/usr/bin/pkg-config --cflags --libs --static opencv4 | xargs g++ -g ${file} -o ${fileDirname}/${fileBasenameNoExtension}",
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
}
]
}