問題描述
需要在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`