【前言】
我们都知道在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/169Download 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就可以开开心心的添加第三方库了!