I want to make use of pkg-config in my Makefile to find the link-path for libspa-0.2.

I observe that pkg-config --libs libspa-0.2 returns nothing.

For simplicity, I'll demonstrate the problem by running pkg-config straight from the shell, i.e. not from within my Makefile.

$ uname -a
Linux MY_LINUX_PC #1 SMP Thu Oct 5 21:02:42 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
$ sudo apt-get install -y libspa-0.2-dev
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following package was automatically installed and is no longer required:
Use 'sudo apt autoremove' to remove it.
Suggested packages:
The following NEW packages will be installed:
0 upgraded, 1 newly installed, 0 to remove and 3 not upgraded.
Need to get 0 B/81.7 kB of archives.
After this operation, 625 kB of additional disk space will be used.
Selecting previously unselected package libspa-0.2-dev:amd64.
(Reading database ... 34966 files and directories currently installed.)
Preparing to unpack .../libspa-0.2-dev_0.3.48-1ubuntu3_amd64.deb ...
Unpacking libspa-0.2-dev:amd64 (0.3.48-1ubuntu3) ...
Setting up libspa-0.2-dev:amd64 (0.3.48-1ubuntu3) ...
$ pkg-config --libs libspa-0.2


Oddly, pkg-config behaves as expected when asked to report libspa-0.2's cflags:

$ pkg-config --cflags libspa-0.2
-D_REENTRANT -I/usr/include/spa-0.2

This is the content of libspa-0.2.pc:

$ cat /usr/lib/x86_64-linux-gnu/pkgconfig/libspa-0.2.pc


Name: libspa
Description: Simple Plugin API
Version: 0.2
Cflags: -I${includedir}/spa-0.2 -D_REENTRANT

...so I was expecting pkg-config --libs libspa-0.2 to return something along the lines of /usr/lib/x86_64-linux-gnu.

Why does pkg-config --libs libspa-0.2 return an empty string?

I'd be grateful if a knowledgeable answerer can describe a little about the relationship between pkg-config, apt-get, and the content of the respective .pc files.

I would like to understand the problem/observed behavior specifically with respect to libspa-0.2-dev, but if there is a generalization, I'd like to learn that as well.

Update: this is weird -- it looks like pkg-config is doing some (intelligent) formatting/stripping of content for the library link-paths. This is the content of zlib.pc -- something preinstalled (which should rule out my messing up):

$ cat /usr/lib/x86_64-linux-gnu/pkgconfig/zlib.pc

Name: zlib
Description: zlib compression library
Version: 1.2.11

Libs: -L${libdir} -L${sharedlibdir} -lz
Cflags: -I${includedir}

...and this this what pkg-config reports for its library link paths:

$ pkg-config --libs zlib

...i.e. it seems to be stripping out the -L${libdir} -L${sharedlibdir} part.

At least the behavior is consistent...which maybe implies this isn't a "problem" but defined behavior of pkg-config. But I can't figure out the rationale of why it's behaving this way: when and why does it strip out the library link-paths, i.e. -L content?


1 Answer 1


Why does pkg-config --libs libspa-0.2 return an empty string?

libspa-0.2 is a headers-only package, it doesn’t ship any libraries. That’s why its .pc file doesn’t specify a Libs entry.

When and why does it strip out the library link-paths, i.e. -L content?

pkg-config strips arguments which are already known to the compiler. On your system, /usr/lib/x86_64-linux-gnu is the default library path and the compiler knows about it, so it doesn’t need to be specified with a -L option. This behaviour can be disabled with the --keep-system-libs option (at least, with the pkgconf implementation of pkgconfig, which is probably what your system uses):

$ pkg-config --keep-system-libs --libs zlib
-L/usr/lib/x86_64-linux-gnu -lz

But it only includes -L if an -l option is actually required, so it doesn’t show up for libspa-0.2:

$ pkg-config --keep-system-libs --libs libspa-0.2

(There’s an equivalent flag for CFLAGS, --keep-system-cflags.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .