在Vscode中配置opencv3.2.0时,记下出现问题的过程,被这个配置过程折磨了很久。作者的环境为ubuntu18.04+Vscode+opencv3.2.0/C++。
在装ROS时ubuntu中已安装好了opecv3.2.0,并配置了C/C++的Vscode安装环境,并不想再次安装其他版本的opencv,配置该版本的opencv3.2.0,安装路径在/usr/include中。
和这位博主这个问题出现的其中一个问题一样,但是并不是launch.json中prelaunchTask中命名和task.josn中的label标签命名一样,并非这个问题,其实还是配置文件的问题,在网上找到很多个版本的配置文件,可能导致配置文件并非适用于自己的安装环境,最后仔细查找配置文件,终于在task.json中的“-g”的下一行找到问题,附下自己的配置文件供大家参考。
task.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "cppbuild",
"command": "g++",
"args": [
"-std=c++11",
"-static-libgcc",
"-Wall", // 开启额外警告
"-g",
"${file}", /我这里写错,写成了"${fileDirname}/*.cpp",之前参考别人的
"-o",
"${fileDirname}/${fileBasenameNoExtension}.out",
"`pkg-config","--cflags","opencv","--libs`",
"-I",
"/usr/include",
"-I",
"/usr/include/opencv",
"-I",
"/usr/include/opencv2",
"-L",
"/usr/lib",
"-I",
"opencv_core",
"-I",
"opencv_imgproc",
"-I",
"opencv_imgcodecs",
"-I",
"opencv_video",
"-I",
"opencv_ml",
"-I",
"opencv_highgui",
"-I",
"opecv_obdetect",
"-I",
"opencv_flann",
"-I",
"opencv_imgcodecs",
"-I",
"opencv_photo",
"-I",
"opencv_videoio"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
]
}
launch.josn
{
"version": "0.2.0",
"configurations": [
{
"name": "g++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"miDebuggerPath": "/usr/bin/gdb",
"preLaunchTask": "build",
//glibc-xxx, error
"sourceFileMap": {
"/build/glibc-uZu3wS": "/usr/src/glibc"
}
}
]
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/",
"/usr/include/opencv2"
],
"defines": [],
"compilerPath": "/usr/bin/g++",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
上面的配置文件供大家参考。
1、首先出现了glibc问题,
无法读取文件‘/build/glibc-S9d2JN/glibc-2.27/csu/libc-start.c‘的一种解决办法‘....
vscode的右下角弹出这个问题,由于没有安装glibc,参考这位博主https://blog.csdn.net/Williamcsj/article/details/121112133安装即可:。 安装完成后并进行配置,即可解决问题。
2.再此出现如下错误
终端中出现如下问题。问题出现在了inshow这个地方,发现是图片路径问题。
参考链接:ubuntu opencv 无法使用绝对路径
这个是我的测试代码。改变路径即可。
#include
#include
#include
using namespace std;
using namespace cv;
int main()
{
// Mat img = imread("dog.jpg");
Mat img = imread("/home/hkk/A/test/dog.jpg"); //换成绝对路径,没有再报错。
imshow("image", img);
cout<<"hello!你好,"<
3.总结
在配置环境过程中,对小白来说,会遇到很多麻烦,参考别人的方式进行安装及配置时,一定要结合自己的环境问题。或者找到比较全的过程进行操作。