简单的说就是向用户向程序提供相应库的路径、版本号等信息的程序
譬如说我们运行以下命令
pkg-config 查看gcc的CFLAGS参数
pkg-config --libs --cflags opencv
显示
-I/usr/include/opencv -lcxcore -lcv -lhighgui -lcvaux
因此当我们需要编译连接某个库时,我们只需要把上面那行加入gcc 的参数里面即可
这也是configure的作用:它会检查你需要的包,产生相应的信息。
它是从包名为xxx.pc这个文件中查找到的。
拿上面那个例子说,它是从opencv.pc这个文件中查知的。
那pkg-config 又怎么会知道opencv.pc这个文件呢?
缺省情况下,pkg-config首 先在prefix/lib/pkgconfig/中查找相关包(譬如opencv)对应的相应的文件(opencv.pc)
在linux上上述路径名为 /usr/lib/pkconfig/
若是没有找到,它也会到PKG_CONFIG_PATH
这个环境变量所指定的路径下去找。
若是没有找到,它就会报 错,例如:
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found
设置环境变量PKG_CONFIG_PATH方法举例如下:
export PKG_CONFIG_PATH=/cv/lib:$PKG_CONFIG_PATH
[root@yx pkgconfig]# cat glib-2.0.pc
prefix=/usr
exec_prefix=/usr
libdir=/lib
includedir=/usr/include
configexecincludedir=/usr/lib/glib-2.0/include
glib_genmarshal=glib-genmarshal
gobject_query=gobject-query
glib_mkenums=glib-mkenums
Name: GLib
Description: C Utility Library
Version: 2.12.3
Libs: -L${libdir} -lglib-2.0
Cflags: -I${includedir}/glib-2.0 -I${configexecincludedir}
[root@yx pkgconfig]# pwd
/usr/lib/pkgconfig
可见.pc
文件 是对其的库文件路径,头文件路径,版本号,Cflags等一些参数进行封装。
上面部分来源于:http://www.cppblog.com/colorful/archive/2012/05/05/173750.html
(我下的是pkg-config-0.29.2.tar.gz)下载地址
解压之后出现deprecated信息以及 目录下的信息;
deprecated信息有人知道怎么解决希望评论一波,强迫症。。。一枚
pkg-config-0.29.2/glib/glib/deprecated/
pkg-config-0.29.2/glib/glib/deprecated/gcompletion.h
pkg-config-0.29.2/glib/glib/deprecated/gthread-deprecated.c
pkg-config-0.29.2/glib/glib/deprecated/grel.h
pkg-config-0.29.2/glib/glib/deprecated/gmain.h
pkg-config-0.29.2/glib/glib/deprecated/gcache.h
pkg-config-0.29.2/glib/glib/deprecated/gcache.c
pkg-config-0.29.2/glib/glib/deprecated/gallocator.h
pkg-config-0.29.2/glib/glib/deprecated/gallocator.c
pkg-config-0.29.2/glib/glib/deprecated/grel.c
pkg-config-0.29.2/glib/glib/deprecated/gcompletion.c
pkg-config-0.29.2/glib/glib/deprecated/gthread.h
cd 进入解压文件夹
root@test-2288H-V5:/home/wang# cd pkg-config-0.29.2
root@test-2288H-V5:/home/wang/pkg-config-0.29.2# ll
total 1704
drwxrwxr-x 4 test test 4096 3月 21 2017 ./
drwxr-x--- 4 wang wang 4096 8月 16 23:57 ../
-rw-rw-r-- 1 test test 372514 3月 21 2017 aclocal.m4
-rw-rw-r-- 1 test test 359 2月 9 2014 AUTHORS
-rw-rw-r-- 1 test test 47305 2月 9 2014 ChangeLog
drwxrwxr-x 7 test test 4096 3月 21 2017 check/
-rwxr-xr-x 1 test test 7333 3月 19 2017 compile*
-rwxr-xr-x 1 test test 42938 9月 27 2015 config.guess*
-rw-rw-r-- 1 test test 2335 3月 21 2017 config.h.in
-rw-rw-r-- 1 test test 2748 3月 21 2017 config.h.win32
-rw-rw-r-- 1 test test 2754 4月 12 2016 config.h.win32.in
-rwxr-xr-x 1 test test 36006 9月 27 2015 config.sub*
-rwxrwxr-x 1 test test 523693 3月 21 2017 configure*
-rw-rw-r-- 1 test test 8585 3月 21 2017 configure.ac
-rw-rw-r-- 1 test test 18092 2月 9 2014 COPYING
-rwxr-xr-x 1 test test 23566 9月 27 2015 depcomp*
-rw-rw-r-- 1 test test 1711 4月 12 2016 detectenv-msvc.mak
drwxrwxr-x 4 test test 4096 3月 21 2017 glib/
-rw-r--r-- 1 test test 15752 9月 27 2015 INSTALL
-rwxr-xr-x 1 test test 14675 9月 27 2015 install-sh*
-rw-r--r-- 1 test test 324089 1月 24 2016 ltmain.sh
-rw-rw-r-- 1 test test 24615 3月 19 2017 main.c
-rw-rw-r-- 1 test test 1794 4月 12 2016 Makefile.am
-rw-rw-r-- 1 test test 38877 3月 21 2017 Makefile.in
-rw-rw-r-- 1 test test 101 4月 12 2016 Makefile.sources
-rw-rw-r-- 1 test test 2620 4月 12 2016 Makefile.vc
-rwxr-xr-x 1 test test 6872 9月 27 2015 missing*
-rw-rw-r-- 1 test test 13138 3月 21 2017 NEWS
-rw-rw-r-- 1 test test 28168 3月 20 2017 parse.c
-rw-rw-r-- 1 test test 1248 3月 19 2017 parse.h
-rw-rw-r-- 1 test test 30963 3月 21 2017 pkg.c
-rw-rw-r-- 1 test test 23611 3月 21 2017 pkg-config.1
-rw-rw-r-- 1 test test 17832 4月 12 2016 pkg-config-guide.html
-rw-rw-r-- 1 test test 4475 3月 19 2017 pkg.h
-rw-rw-r-- 1 test test 10253 3月 21 2017 pkg.m4.in
-rw-rw-r-- 1 test test 2599 2月 9 2014 README
-rw-rw-r-- 1 test test 2413 4月 12 2016 README.win32
-rw-rw-r-- 1 test test 4037 4月 12 2016 rpmvercmp.c
-rw-rw-r-- 1 test test 617 4月 12 2016 rpmvercmp.h
./configure --with-internal-glib
root@test-2288H-V5:/home/wang/pkg-config-0.29.2# ./configure --with-internal-glib
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking how to print strings... printf
checking for style of include used by make... GNU
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
make这里有warning,查了一些资料emmm不好不好,有大佬知道如何解决,可以附在评论,我学习一下,完善资料。
make[6]: Entering directory '/home/wang/pkg-config-0.29.2/glib/glib'
CC libglib_2_0_la-gallocator.lo
CC libglib_2_0_la-gcache.lo
CC libglib_2_0_la-gcompletion.lo
CC libglib_2_0_la-grel.lo
CC libglib_2_0_la-gthread-deprecated.lo
CC libglib_2_0_la-garray.lo
CC libglib_2_0_la-gasyncqueue.lo
CC libglib_2_0_la-gatomic.lo
CC libglib_2_0_la-gbacktrace.lo
gbacktrace.c: In function ‘g_on_error_query’:
gbacktrace.c:177:5: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result]
fgets (buf, 8, stdin);
^
gbacktrace.c: In function ‘stack_trace’:
gbacktrace.c:301:18: warning: ignoring return value of ‘dup’, declared with attribute warn_unused_result [-Wunused-result]
close (0); dup (in_fd[0]); /* set the stdin to the in pipe */
^
gbacktrace.c:302:18: warning: ignoring return value of ‘dup’, declared with attribute warn_unused_result [-Wunused-result]
close (1); dup (out_fd[1]); /* set the stdout to the out pipe */
^
gbacktrace.c:303:18: warning: ignoring return value of ‘dup’, declared with attribute warn_unused_result [-Wunused-result]
close (2); dup (out_fd[1]); /* set the stderr to the out pipe */
^
gbacktrace.c:318:3: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
write (in_fd[1], "backtrace\n", 10);
^
gbacktrace.c:319:3: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
write (in_fd[1], "p x = 0\n", 8);
^
gbacktrace.c:320:3: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
write (in_fd[1], "quit\n", 5);
make check
make install
pkg-config -list-all
细节如下:
root@test-2288H-V5:/home/wang/pkg-config-0.29.2# pkg-config -list-all
Unknown option -list-all
root@test-2288H-V5:/home/wang/pkg-config-0.29.2# pkg-config --list-all
iso-codes iso-codes - ISO country, language, script and currency codes and translations
systemd systemd - systemd System and Service Manager
pm-utils pm-utils - Power management scripts for suspend and hibernate
kbproto KBProto - KB extension headers
fixesproto FixesProto - X Fixes extension headers
usbutils usbutils - USB device database
xkeyboard-config XKeyboardConfig - X Keyboard configuration data
inputproto InputProto - Input extension headers
xextproto XExtProto - XExt extension headers
xbitmaps X bitmaps - Bitmaps that are shared between X applications
adwaita-icon-theme gnome-icon-theme - A collection of icons used as the basis for GNOME themes
mobile-broadband-provider-info mobile-broadband-provider-info - Mobile Broadband Service Provider Information Database
libquvi-scripts libquvi-scripts - Scripts for libquvi
fontutil FontUtil - Font utilities dirs
poppler-data poppler-data - Encoding files for use with poppler
udev udev - udev
bash-completion bash-completion - programmable completion for the bash shell
yelp-xsl yelp-xsl - Yelp XSLT Stylesheets
xtrans XTrans - Abstract network code for X
xproto Xproto - Xproto headers
xorg-sgml-doctools xorg-sgml-doctools - Stylesheets and entities for X.Org documentation
shared-mime-info shared-mime-info - Freedesktop common MIME database
root@test-2288H-V5:/home/wang/pkg-config-0.29.2#
至此, pkg-config 安装完成。