问题描述
需要在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`