关于pkg-config的说明:
为了解决引用各种第三方库时的cflags和ldflags的设置问题,pkg-config被引进到编译配置中来,以便为了用一种统一的方式来自动设置项目所依赖cflags和ldflags等参数,
pkg-config是通过库提供的一个 .pc 文件获得库的各种必要信息的,包括版本信息、编译和连接需要的参数等。这些信息可以通过 pkg-config提供的参数单独提取出来直接供编译器和连接器使用。
官方的说明如下:
The pkgconfig package contains tools for passing the include path and/or library paths to build tools during the make file execution.
pkg-config is a function that returns meta information for the specified library.
The default setting for PKG_CONFIG_PATH is /usr/lib/pkgconfig because of the prefix we use to install pkgconfig.You may add to PKG_CONFIG_PATH by exporting additional paths on your system where pkgconfig files are installed.Note that PKG_CONFIG_PATH is only needed when compiling packages, not during run-time.
-----------------------------------------------
pkg-config的使用本来非常简单,但是我今天晚上遇到了一个极其诡异的事情, pkg-config 不认识配置文件中的${prefix}了
如下,假设我有一个libavcodec.pc内容如下:
prefix=/home/ffmpeg_build
exec_prefix=${prefix}
libdir=${prefix}/lib
includedir=${prefix}/include
Name: libavcodec
Description: FFmpeg codec library
Version: 52.47.0
Requires:
Requires.private: libavutil = 50.7.0
Conflicts:
Libs: -L${libdir} -lavcodec
Libs.private: -lz -lbz2 -lm -lvfw32 -LE:/msys/local/lib -ldirac_encoder -ldirac_decoder -lm -lstdc++ -LE:/msys/local/lib -ldirac_encoder -ldirac_decoder -lm -lstdc++ -lfaac -lfaad -lgsm -lmp3lame -lm -lopencore-amrnb -lm -lopencore-amrwb -lm -lopenjpeg -LE:/msys/local/lib -lschroedinger-1.0 -loil-0.3 -lm -lspeex -ltheoraenc -ltheoradec -logg -lvorbisenc -lvorbis -logg -lx264 -lm -lxvidcore -lws2_32 -lvfw32 -lpthreadGC2 -lstdc++
Cflags: -I${includedir}