无法使用pkg配置在VSCode中启动外部程序

Failed to launch external program in VSCode with pkg-config

本文关键字:VSCode 启动 外部 程序 配置 pkg      更新时间:2023-10-16

我创建了一个简单的main.cpp。我还创建了.vscode文件夹下的tasks.json,如下所示。

{
  // 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在终端中正常运行。然而,它在vscode中的任务运行器中不起作用。错误消息为

无法启动外部程序g++$(pkg config--cflags--libs-opencv)

有什么建议吗?

我让我的程序处理以下任务。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" }

您必须用"like so"pkg-config", "--cflags", "--libs", "opencv来分隔每个命令。希望能有所帮助。