Skip to content

pkg-config

Very.. Terse..

list all packages
pkg-config --list-all
libraries
pkg-config --libs apr-1
-lapr-1
cflags
pkg-config --cflags apr-1
-DLINUX -D_REENTRANT -D_GNU_SOURCE -I/usr/include/apr-1.0

missing config

For instance, gtest had no gtest.pc file on servert1. That can be helped: Find the search path for pkconfig :

variable
pkg-config --variable pc_path pkg-config
/usr/local/lib/x86_64-linux-gnu/pkgconfig:/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig

Now pick a directory from there that exists, for instance :

pc directory
ls -l /usr/lib/pkgconfig
gdal.pc  gss.pc  luabind.pc  shishi.pc

Now put a file like this called gtest.pc in there :

gtest example
prefix=/usr/local
exec_prefix=${prefix}
libdir=${prefix}/lib
includedir=${prefix}/include

Name: gtest
Description: gtest
Version: 1.8.0
Libs: -L${libdir} -lgtest -lpthread
Cflags: -I${includedir}

pkconfig now at least returns those values, of course some checking needs to be done is those directories are correct.

details

Source : visit

Some more details now, for one pkg-config works with pkg-config files which end in .pc and are stored in a default directory for pkg-config, on debian jessie it seems to be multiple directories :

directories
1
2
3
/usr/share/pkgconfig/
/usr/lib/x86_64-linux-gnu/pkgconfig
/usr/local/lib/pkgconfig

An example .pc file for the package libmongocxx is :

.pc file
prefix=/usr/local
includedir=${prefix}/include
libdir=${prefix}/lib

Name: libmongocxx
Description: The MongoDB C++11 Driver Library
URL: http://github.com/mongodb/mongo-cxx-driver
Version: 3.1.1
Requires.private: libbson-1.0 >= 1.5.0, libmongoc-1.0
Requires: libbsoncxx >= 3.1.1
Cflags: -I${includedir}/mongocxx/v_noabi
Libs: -L${libdir} -lmongocxx

Most installations scripts also take care of the pkg-config file, like this one.After doing 'make install' this file was installed and this command works :

mongo
1
2
3
pkg-config --cflags --libs libmongocxx

-I/usr/local/include/mongocxx/v_noabi -I/usr/local/include/libmongoc-1.0 -I/usr/local/include/bsoncxx/v_noabi -I/usr/local/include/libbson-1.0 -L/usr/local/lib -lmongocxx -lbsoncxx