ubuntu18.04 PC 上多版本Opencv并存的设置方法

7 篇文章 0 订阅
4 篇文章 0 订阅

   

目录

一、相关信息

二、具体设置

1.安装XXX.pc文件到pkgconfig 目录

2.设置pkg-config 路径(环境变量)

3.测试XXX.pc与pkg-config设置的准确性

(1).注意事项

(2).设置编译器链接库路径

(3).然后要做的是刷新

(4).最后当然是统测试

4.附件

1. opencv4.pc

2. opencv3arm.pc



一、相关信息

              本机需要用到PC 与arm两个版本的opencv,版本与安装路径见下:

pc:opencv-4.1.0

安装目录:/home/li/usr/mybuild

库目录:/home/li/usr/mybuild/myinstall/lib

头文件目录:/home/li/usr/mybuild/myinstall/include/opencv4/opencv2
arm:opencv-3.4.2

安装目录:/usr/local/arm/opencv342

库目录:/usr/local/arm/opencv342/lib

头文件目录:/usr/local/arm/opencv342/include/opencv

头文件目录:/usr/local/arm/opencv342/include/opencv2

注意:3X 版本有两个库目录。

二、具体设置

1.安装XXX.pc文件到pkgconfig 目录

opencv3X版本在cmake时自动生成opencv.pc文件,4X版本默认不会产生.pC,需要在cmake设置时选择:OPENCV_GENRATE_PKGCONFIG ...选项。文件一般在安装版目录的~/lib/pkgconfig目录里。

把3X版的opencv.pc改名为opencv3arm.pc,4X的改名为opencv4.pc。并且把两个文件放在同一个目录里。我这里是放在/usr/local/arm/opencv342/lib/pkgconfig下。

2.设置pkg-config 路径(环境变量)

sudo vim /etc/bash.bashrc

加入以下路径

export PKG_CONFIG_LIBDIR=/usr/local/arm/opencv342arm/lib/pkgconfig
#PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/arm/opencv342arm/lib/pkgconfig
export PKG_CONFIG_PATH
//注意:LIBDIR比PATH优生级高,一般情况可以用PATH,也就是注解掉的那段。

保存后刷新环境变量:

source /etc/bash.bashrc

3.测试XXX.pc与pkg-config设置的准确性

//测试pc版本号:
~$ pkg-config --modversion opencv4
4.1.0
//测arm版:~$ pkg-config --modversion opencv3arm
3.4.2

测XXX.pc文件是否准确

//测PC版:
~$ pkg-config --cflags --libs opencv4
-I/home/li/usr/mybuild/myinstall/include/opencv4/opencv2 -I/home/li/usr/mybuild/myinstall/include/opencv4 -L/home/li/usr/mybuild/myinstall/lib -lopencv_dnn -lopencv_gapi -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_video -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_flann -lopencv_videoio -lopencv_imgcodecs -lopencv_imgproc -lopencv_core
//测arm版
~$ pkg-config --cflags --libs opencv3arm
-I/usr/local/arm/opencv342arm/include/opencv -I/usr/local/arm/opencv342arm/include -L/usr/local/arm/opencv342arm/lib -lopencv_dnn -lopencv_ml -lopencv_objdetect -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_imgproc -lopencv_flann -lopencv_core

其中显示了库与头文件路径及安装的所有库名称。

(1).注意事项

你以为通过上面的配置就能编译出程序了?事实证明你把Linux想得太简单了!它就是喜欢折磨人!如果不做这一步设置,你在GCC编译时就会出错:

 error while loading shared libraries: libopencv_core.so.3.2: cannot open shared object file: No such file or directory

(2).设置编译器链接库路径

以上错误提示实质是GCC没有找到opencv的库文件,大家坐好认真上课。

打开 /etc/ld.so.conf.d 目录
并新建两个 XXX.conf文件
文件名与XXX.PC相同
opencv3arm.conf
opencv4.conf
只有这样,系统才能识别具体是哪个版本!
切记!切记!切记!

。。。。。。

(3).然后要做的是刷新

ldconfig

(4).最后当然是编译测试

// PC 版测试:
~$ g++ camtest1.cpp -o campc `pkg-config --cflags --libs opencv4`
//时间嘀嗒嘀嗒
~$
//OK,没错误提示!
// arm 版测试:
~$ aarch64-linux-g++ camtest1.cpp -o camarm `pkg-config --cflags --libs opencv3arm`
// 时间又嘀嗒嘀嗒
~$
// OK,没错误提示!
// 我的arm cpu 是三星的S5P6818,1.4GX8核。编译器是aarch64-linux-gnu

 

4.附件


附两版本XXX .PC文件

1. opencv4.pc

# opencv4.pc for PC
# Package Information for pkg-config

prefix=/home/li/usr/mybuild/myinstall
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir_old=${prefix}/include/opencv4/opencv2
includedir_new=${prefix}/include/opencv4

Name: OpenCV
Description: Open Source Computer Vision Library
Version: 4.1.0
Libs: -L${exec_prefix}/lib -lopencv_dnn -lopencv_gapi -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_video -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_flann -lopencv_videoio -lopencv_imgcodecs -lopencv_imgproc -lopencv_core
Libs.private: -ldl -lm -lpthread -lrt
Cflags: -I${includedir_old} -I${includedir_new}

2. opencv3arm.pc

# opencv3arm.pc for arm
# Package Information for pkg-config

prefix=/usr/local/arm/opencv342arm
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir_old=${prefix}/include/opencv
includedir_new=${prefix}/include

Name: OpenCV
Description: Open Source Computer Vision Library for arm_64
Version: 3.4.2
Libs: -L${exec_prefix}/lib -lopencv_dnn -lopencv_ml -lopencv_objdetect -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_imgproc -lopencv_flann -lopencv_core
Libs.private: -ldl -lm -lpthread -lrt
Cflags: -I${includedir_old} -I${includedir_new}

版权所有!转载请说明出处并附链接。

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值