关于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} -----------------------------------
理论上我如果用执行如下命令:
pkg-config --libs libavcodec
则应该输出:
-L/home/ffmpeg_build/lib -lavcodec
但是我这边却出现了如下诡异的输出:
-L/usr/local/lib -lavcodec
也就是说${prefix}的设置被忽略了, 在pkg-config看来你无论设置任何值,${prefix}永远都是 /usr/local
这就使得所有prefix不是/usr/local的第三方软件在用pkg-config来侦测的时候都失败
我暂时将我的prefix也设置成了/usr/local,虽然这最终解决我的问题,但我还是想知道问题的根源是什么?
继续查资料中.......
(psusong) |