Vscode 配置opencv的tasks.json

問題描述

需要在main.cpp文件中調用opencv庫, 在debug時提示錯誤:
/usr/include/opencv2/core/cvstd.hpp:664: undefined reference to cv::XXXXX'
這裏XXXX代表一些API,

原因是未鏈接opencv庫

解決辦法

在tasks.json文件中增加args參數:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "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"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build"
        }
    ]
}

核心思想就是在args中增加

`pkg-config --cflags --libs opencv`

注意, 是鍵盤左上角的~按鍵.
但是寫的方式要按照我上面寫的方式, 把這一句話分成四段!!!
這樣就可以debug了.
在命令行的書寫方式是:

g++ -g main.cpp -o main `pkg-config --cflags --libs opencv`
發佈了72 篇原創文章 · 獲贊 65 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章