问题
I have created a simple main.cpp. I have also created a tasks.json under .vscode folder which is as follow.
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "g++ $(pkg-config --cflags --libs opencv)",
"isShellCommand": true,
"args": ["main.cpp"],
"showOutput": "always"
}
g++ $(pkg-config --cflags --libs opencv) main.cpp
is running properly in terminal. However, it's not working in the task runner in vscode. The error message is
Failed to launch external program g++ $(pkg-config --cflags --libs opencv)
Any suggestion for that ?
回答1:
I got my program to work with the following tasks.json:
{
"tasks": [
{
"type": "shell",
"label": "g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"`pkg-config", "--cflags", "--libs", "opencv`"
],
"options": {
"cwd": "/usr/bin"
}
}
],
"version": "2.0.0" }
You have to separate each command with "" like so "pkg-config", "--cflags", "--libs", "opencv
". Hope that helps.
来源:https://stackoverflow.com/questions/38565074/failed-to-launch-external-program-in-vscode-with-pkg-config