I installed a library via apt but it added no .pc file to the pkg-config dir. When I built another manually it got added. Is there a convention for libs automatically creating a .pc file and if so when and how is it done?
Convention for adding .pc files for pkg-config
librariespkg-config
Related Solutions
Apparently it installed in /usr/local/lib which is a non-standard place?
It's a standard place, but sometimes systems are configured presuming that you are not going to build-install anything, and so it is left out of the linker cache path.
Where and how do I install my C libs? (Perhaps the same place yum installs them?)
That is generally a bad idea, esp. if there are potentially distro packages -- now, or down the line -- that conflict. Stick with /usr/local.
Check to see if /usr/local/lib
is in ld.so.cache by running ldconfig -v 2>&1 | grep /usr/local
. If you don't get any output, create a file /etc/ld.so.conf.d/local.conf
with one line:
/usr/local/lib
Run that ldconfig
line again and this time you should see it. You need to run ldconfig every time you build and install a library from source.
I can't manage to compile a simple program that uses this library
Because you have to pass the pkg-config
parameters to the compiler. First, you need to find the actual gsl.pc
.
find /usr/local -name gsl.pc
I think it is more likely in /usr/local/lib/pkgconfig
, and not /usr/local/pkgconfig
as you say. Try pkg-config --list-all | grep gsl
and see if it's found. If not export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
(or whatever the directory with gsl.pc is) and try again. When you get that right, you may want to add it somewhere in, e.g., /etc/profile.d
.
Now, to actually compile:
gcc gsl_erf.c -o gsl `pkg-config --libs --cflags gsl`
You don't need to include -I
and -L
yourself; that's what pkg-config
is for, although all you were likely missing before was -lgsl
.
Stuff in /usr/local
usually supersedes stuff in /usr
, so I'm a bit confused as to why you would install libraries there to have a "a nice custom distro", but then not want to compile against them. Those are the libraries the system will use actually use.
Anyway, man pkg-config
claims the base search path:
is libdir/pkgconfig:datadir/pkgconfig where libdir is the libdir for pkg-config and datadir is the datadir for pkg-config when it was installed.
This implies they are compiled in. I notice it is different on ubuntu than fedora -- the former is long and inclusive, whereas the latter is short and exclusive; on fedora I have to set a $PKG_CONFIG_PATH
to include /usr/local
.
Since paths in $PKG_CONFIG_PATH
are checked first, you could just set:
PKG_CONFIG_PATH=/usr/lib/i386-linux-gnu/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig
The fact that these are at the end of the built-in paths won't matter; if the check makes it to there without finding anything, there's nothing to be found.
To demonstrate how this works, create a temporary directory /opt/bs/pkg
and copy a .pc
file from one of the directories in the default path into it -- e.g., alsa.pc
. First check;
> pkg-config --libs alsa
-lasound
Now go into /opt/bs/pkg/alsa.pc
and change -lasound
(it's in the Libs:
field) to -foobar
. Set $PKG_CONFIG_PATH
and try again:
> PKG_CONFIG_PATH=/opt/bs/pkg pkg-config --libs alsa
-foobar
Eureka, $PKG_CONFIG_PATH
has overridden the built-in paths...you can delete /opt/bs/pkg
, of course.
Best Answer
Like .so symlinks and .h header files, the .pc files are not be shipped in libXXX debian packages, but in the accompanying libXXX-dev packages as they are only useful when developing against that library.