pkg-config安装比较简单,Debian apt-get install pkg-config
Mac brew install pkg-config
一般项目主要使用 pkg-config 的两个命令,例如opencv安装后,在Makefile中配置opencv的路径, pkg-config --cflags opencv
、pkg-config --libs opencv
来在编译阶段寻找opencv 的include 目录以及在链接阶段寻找libs目录
pkg-config 能够找到正确路径的前提是需要配置 $(progam).pc 文件,例如 pkg-config --cflags opencv
命令能正常工作的前提就是需要在pkg-config 的配置扫描路径下有 opencv.pc 文件
pkg-config 的默认扫描路径大概有这么几个地方: /usr/local/share/pkgconfig、 /usr/lib/pkgconfig、/usr/local/lib/pkgconfig 可通过pkg-config --variable pc_path pkg-config
查询
有文档指出也能通过环境变量 PKG_CONFIG_PATH 进行指定,但是直接去默认扫描路径定义对应的.pc文件更直接
Mac 上brew安装的开发包一般会在/usr/local/lib/pkgconfig 下建立软链
.pc文件定义,可以直接参考pkg-config 的默认扫描路径下其他.pc文件的写法,或者参考下面的配置文件opencv.pc
prefix=/usr/local/Cellar/opencv/4.2.0_3
exec_prefix=${prefix}
Name: opencv
Description: Open source computer vision library
Requires:
Version: 4.2.0_3
Libs: ${prefix}/lib/libopencv_calib3d.dylib -lopencv_calib3d ${prefix}/lib/libopencv_core.dylib -lopencv_core ${prefix}/lib/libopencv_features2d.dylib -lopencv_features2d ${prefix}/lib/libopencv_flann.dylib -lopencv_flann ${prefix}/lib/libopencv_highgui.dylib -lopencv_highgui ${prefix}/lib/libopencv_imgproc.dylib -lopencv_imgproc ${prefix}/lib/libopencv_ml.dylib -lopencv_ml ${prefix}/lib/libopencv_objdetect.dylib -lopencv_objdetect ${prefix}/lib/libopencv_photo.dylib -lopencv_photo ${prefix}/lib/libopencv_stitching.dylib -lopencv_stitching ${prefix}/lib/libopencv_superres.dylib -lopencv_superres ${prefix}/lib/libopencv_video.dylib -lopencv_video ${prefix}/lib/libopencv_videostab.dylib -lopencv_videostab ${prefix}/lib/libopencv_imgcodecs.dylib -lopencv_imgcodecs
Cflags: -I${prefix}/include/opencv4 -I${prefix}/include/opencv4/opencv2 -std=gnu++11
网友评论