Windows下的Qt配置pkg-config环境的解决方案!

1 篇文章 0 订阅
【前言】
    我们都知道在Linux系统下配置完opencv环境后,Qt直接按照以下方式就可以直接调用了!这里我们采用的编译器是mingw32-make!
CONFIG += link_pkgconfig
PKGCONFIG += opencv  
    但在windows下面,要么在VS下配置include和lib目录,针对Qt Creator下的多数采用下面的方案:
INCLUDEPATH += D : \ opencv \ build \ include

LIBS += D : \ opencv - build \ bin \ libopencv_core320.dll
LIBS += D : \ opencv - build \ bin \ libopencv_highgui320.dll
LIBS += D : \ opencv - build \ bin \ libopencv_imgcodecs320.dll
LIBS += D : \ opencv - build \ bin \ libopencv_imgproc320.dll
LIBS += D : \ opencv - build \ bin \ libopencv_features2d320.dll
LIBS += D : \ opencv - build \ bin \ libopencv_calib3d320.dll
    如果只使用opencv或许没啥问题,但是往往我们还需要其它第三方的c++库,这时采用这样的方式,工程管理上比较混乱!随无伤大雅,但总觉得别扭!

针对这样的情况,我们往往采用两种方案,分别为Cmake和pkg-config这两种!CMake的确很优秀,但不自动管理Qt自己的内部库,相当于Qt库和第三方库一视同仁,都需要自己配置,这就尴尬了!一般比较复杂且需要跨平台部署的工程才建议使用cmake,平时也没必要自己折腾自己了!

于是下面讨论是pkg-config的方案!
On   http://sourceforge.net/p/mingw/mailman/message/31908633/   there are some instructions from earlier this year:
The FAQ pkg-config information did not work for me: these did: https://github.com/texane/stlink/issues/169
Download these three glib, pkg-config, pkg-config-dev archives and extract contents to C:\MinGW
I keep this unaccepted in case someone has a better answer.
最新的pkg-config是0.29的版本,这里是0.28的!pkg-config这个工具比较稳定了,更新频次比较少!0.28与0.29的区别不大,使用是没有问题的!

下载上面的三个工具,分别为glib,pkg-config,pkg-config-dev。将其放置到mingw的安装目录中!这里我使用的是Qt自带的mingw,你可以完全像我这样设置!

将其分别解压,目录结构分别为




将他们目录下文件夹分别拷贝到mingw的安装目录!

在lib目录下创建一个pkgconfig,用于放置opencv.pc文档!

我们最好再设置一下PKG_CONFIG_PATH


现在我们需要找到opencv.pc,将其复制过来并编辑配置一下!

将其拷贝到刚才的PKG_CONFIG_PATH所对应的目录下!
需要注意的是这个opencv.pc文档在widnows下需要修改一下,否则不好使用!
原本的opencv.pc的内容如下
# Package Information for pkg-config

prefix=D:/OpenCV/build/install
exec_prefix=${prefix}
libdir=${exec_prefix}/x86/mingw/lib
includedir_old=${prefix}/include/opencv
includedir_new=${prefix}/include

Name: OpenCV
Description: Open Source Computer Vision Library
Version: 3.3.1
Libs: -L${exec_prefix}/x86/mingw/lib -llibopencv_dnn331d.dll -llibopencv_ml331d.dll -llibopencv_objdetect331d.dll -llibopencv_shape331d.dll -llibopencv_stitching331d.dll -llibopencv_superres331d.dll -llibopencv_videostab331d.dll -llibopencv_calib3d331d.dll -llibopencv_features2d331d.dll -llibopencv_highgui331d.dll -llibopencv_videoio331d.dll -llibopencv_imgcodecs331d.dll -llibopencv_video331d.dll -llibopencv_photo331d.dll -llibopencv_imgproc331d.dll -llibopencv_flann331d.dll -llibopencv_core331d.dll
Libs.private: -lopengl32 -lglu32
Cflags: -I${includedir_old} -I${includedir_new}


这里我们可以看到上面有prefix,exec_prefix这样的变量,在windows下的pkg-config是无视他们的,都是默认到mingw的安装目录,因此我们需要改为绝对路径!这里设定你自己的目录就可以了!
# Package Information for pkg-config

libdir=D:/OpenCV/build/install/x86/mingw/lib
includedir_old=D:/OpenCV/build/install/include/opencv
includedir_new=D:/OpenCV/build/install/include

Name: OpenCV
Description: Open Source Computer Vision Library
Version: 3.3.1
Libs: -LD:/OpenCV/build/install/x86/mingw/lib -llibopencv_dnn331d.dll -llibopencv_ml331d.dll -llibopencv_objdetect331d.dll -llibopencv_shape331d.dll -llibopencv_stitching331d.dll -llibopencv_superres331d.dll -llibopencv_videostab331d.dll -llibopencv_calib3d331d.dll -llibopencv_features2d331d.dll -llibopencv_highgui331d.dll -llibopencv_videoio331d.dll -llibopencv_imgcodecs331d.dll -llibopencv_video331d.dll -llibopencv_photo331d.dll -llibopencv_imgproc331d.dll -llibopencv_flann331d.dll -llibopencv_core331d.dll
Libs.private: -lopengl32 -lglu32
Cflags: -I${includedir_old} -I${includedir_new}


好了,pkg-config环境配置都完成了!

pro工程目录下添加
CONFIG += link_pkgconfig
PKGCONFIG += opencv  
就可以构建使用了!

这样我们就可以拥抱qmake了,无需需要cmake就可以开开心心的添加第三方库了!
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值