1.首先,什么是pkg-config:
pkg-config 当你从源代码编译软件时,用来提供依赖库的信息的软件。pkg-config原本是设计用于Linux的,但现在在各个版本的BSD、windows、Mac OS X和Solaris上都有着可用的版本。它输出已安装的库的各个信息,包括:1)C或C++编译器需要的参数2)链接器需要的参数3)已安装软件包的版本信息2.什么时候用的着?
当在Linux/Unix重 编写完程序,开始编译(寻找头文件)和链接(寻找链接库)时,就用上它了。3.怎么用?
最常用的有:1:pkg-config --libs --cflags 输出:编译和链接使用-I/usr/local/include/opencv -I/usr/local/include -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
2:pkg-config --libs 输出:链接器使用 -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
3:pkg-config --cflags 输出: 编译器使用 -I/usr/local/include/opencv -I/usr/local/include
4.最后:pkg-config工作原理:命令的输出来源于那里呢?
pkg-config命令通过检索存放于系统的*.pc文件来给出相应的库的输出。比如,如果在系统中安装了opencv库,则对应的在系统中存放着opencv.pc;而这个文件就记录着opencv库的版本、编译参数、链接参数等信息。pkg-config搜索过程:1:opencv was found in the pkg-config search path.2: you should add the directory containing `opencv.pc' to the PKG_CONFIG_PATH environment variable
# Package Information for pkg-config这个文件来源于那里呢?这个*.pc文件在你的库安装包里,一般是库的打包者或发行者设置好的。当安装库时,*.pc文件被放于你系统重的某一个文件夹中(根据你的系统设置,一般存放的位置有/usr/lib/pkgconfig/等)。--cflags 输出:
prefix=/usr/local
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir_old=${prefix}/include/opencv
includedir_new=${prefix}/include
Name: OpenCV
Description: Open Source Computer Vision Library
Version: 3.2.0
Libs: -L${exec_prefix}/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
Libs.private: -ldl -lm -lpthread -lrt
Cflags: -I${includedir_old} -I${includedir_new}
Cflags: -I${includedir_old} -I${includedir_new}--libs 输出:
-L${exec_prefix}/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