Sample Header Ad - 728x90

When/why doesn't pkg-config return library link-path?

0 votes
1 answer
284 views
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 5.15.133.1-microsoft-standard-WSL2 #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:
  libwebrtc-audio-processing1
Use 'sudo apt autoremove' to remove it.
Suggested packages:
  pipewire-doc
The following NEW packages will be installed:
  libspa-0.2-dev
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
prefix=/usr
libdir=${prefix}/lib/x86_64-linux-gnu
includedir=${prefix}/include

plugindir=${libdir}/spa-0.2

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
prefix=/usr
exec_prefix=${prefix}
libdir=${prefix}/lib/x86_64-linux-gnu
sharedlibdir=${libdir}
includedir=${prefix}/include

Name: zlib
Description: zlib compression library
Version: 1.2.11

Requires:
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
-lz
$
...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?
Asked by StoneThrow (1937 rep)
Dec 8, 2023, 08:24 PM
Last activity: Dec 12, 2023, 02:45 PM