安装好后opencv后执行下面这条语句的时候出错:
pkg-config --cflags opencv
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found
原因: 缺失了opencv.pc这个配置信息文件
解决方法: 创建opencv.pc文件,注意添加的路径
cd /usr/local/lib
ls pkgconfig // 如果没有该文件夹 进行创建 一般都有
sudo mkdir pkgconfig
cd pkgconfig
sudo touch opencv.pc // 查看是否有opencv4.pc 有的话复制一下
然后在opencv.pc中添加以下信息,注意这些信息需要与自己安装opencv时的库路径对应:
prefix=/usr/local
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib
Name: opencv
Description: The opencv library
Version:4.0.1
Cflags: -I${includedir}/opencv4
Libs: -L${libdir} -lopencv_shape -lopencv_stitching -lopencv_objdetect -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core
保存退出,然后将文件导入到环境变量:
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
再执行 pkg-config --cflags --libs opencv时输出结果如下:文章来源:https://www.toymoban.com/news/detail-606152.html
-I/usr/local/include/opencv4 -L/usr/local/lib \
-lopencv_shape -lopencv_stitching -lopencv_objdetect \
-lopencv_superres -lopencv_videostab -lopencv_calib3d \
-lopencv_features2d -lopencv_highgui -lopencv_videoio \
-lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml \
-lopencv_imgproc -lopencv_flann -lopencv_core
然后进行 make 如果还是有问题 make之前先make clean 再次尝试 一般都会成功
还是有问题的话 看一下MakeFile 文件 是否添加opencv的头文件和库文件路径文章来源地址https://www.toymoban.com/news/detail-606152.html
到了这里,关于Package opencv was not found in the pkg-config search path.opencv.c问题的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!