【问题标题】:C++ Tasks.json VS Code not taking arguments correctlyC++ Tasks.json VS Code 没有正确接受参数
【发布时间】:2022-12-10 18:12:26
【问题描述】:

此处的初学者使用 C/C++ 文件构建任务配置。因为我每次都必须在终端中输入以下命令;这完美地编译了我的代码。

g++ Test.cpp -I/usr/include/opencv4 $(pkg-config --libs opencv4) -o Test

但是当我想使用 tasks.json 直接运行代码时,我已经设置了这样的配置。

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++ build active file",
            "command": "/usr/bin/g++",
            "args": [
                "${file}",
                "-I/usr/include/opencv4 $(pkg-config --libs opencv4)",
                "-o",
                "${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

但是当运行这个任务时,它会像提供的屏幕截图中那样给出错误。

我应该在 args 数组中放入什么来解决这个问题?

【问题讨论】:

    标签: c++ json visual-studio-code


    【解决方案1】:

    所以,我让它工作,但将每个单独的库设置为 args 数组中的单独字符串,这是代码所要求的。现在 args 键应该如下所示:

    "args": [
                    "-I/usr/include/opencv4",
                    "-lopencv_imgcodecs",
                    "-lopencv_highgui",
                    "-lopencv_imgproc",
                    "-lopencv_core",
                    "${file}"
            ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多