libpkg-config/0.1.1

[brief]

C library for retrieving compiler/linker flags and other metadata

The libpkg-config library provides a C API for retrieving C-language family compiler/linker flags and other metadata from pkg-config files (.pc). It's primarily aimed at build system and other similar tools (see the recommended usage below).

This library is a fork of libpkgconf from the pkgconf project. The fork was motivated by the poor quality of changes in general (see these three commits for a representative example: 0253fdd c613eb5 ab404bc) and disregard for backwards compatibility in particular (for example, sr.ht/18). While we have removed a large amount of non-essential functionality and "innovations" as well as spend some time fixing and cleaning things up, make no mistake it is still an over-engineered, inscrutable mess and there likely are bugs in the corner cases. However, we do use it in build2, which means at least the recommended usage patterns (see below) are reasonably well tested. We hope to continue cleaning things up as time permits but a complete rewrite is also on the cards (in which case it will most likely become a C++ library).

Recommended usage

Traditionally, pkg-config is used like this: instead of just passing -lfoo during linking, we call pkg-config --cflags foo passing the returned options during compilation and then call pkg-config --libs foo passing the returned options and libraries during linking. In other words, instead of letting the compiler find libfoo.a or libfoo.so (or their equivalents on other platforms) using its library search paths, we rather let pkg-config find foo.pc using its .pc file search paths.

This works reasonably well if the two sets of search paths are consistent, which is normally the case for the native compilation using standard installation locations. For example, if our C/C++ toolchain is configured to look for libraries in /usr/local/lib and /usr/lib and our pkg-config is configured to look for .pc files in /usr/local/lib/pkgconfig and /usr/lib/pkgconfig, then everything will most likely work smoothly.

However, if these two sets of search paths start diverging, for example due to custom installation locations, cross-compilation, etc., then things will most likely not go smoothly at all. The traditional pkg-config answer to this type of problems is an array of environment variables to tweak various aspects of the search paths, the sysroot rewrite logic, and, in case of pkgconf, the cross-personality functionality.

However, an astute reader will undoubtedly notice that at the root of our troubles are the two sets of search paths that have the inevitable tendency to become inconsistent (as all search paths tend to do). And if only we could go back to the one set, the single source of truth, then all our troubles will likely disappear and we won't need an impressive list of hacks and workarounds.

We've decided to go with this approach in build2. As a step one, we collect exactly the same library search paths as what will be used by the compiler. Specifically, we parse the linker options specified by the user and collect all the paths specified with -L. Then we extract the system library search paths by running the compiler with -print-search-dirs (this option is supported by both GCC and Clang).

Next, from this list of library search paths we derive a parallel list of the .pc file search paths. On most platforms this is a matter of just appending the pkgconfig subdirectory to each library search path (of course, someone had to be different and in this case it is FreeBSD).

Finally, we initialize the libpkg-config's pkg_config_client::dir_list only with these .pc file search paths omitting all the built-in paths and environment variables.

(To be precise, in build2 we go a step further and search for the library ourselves, then locate the corresponding .pc file, if any, and load it directly. This removes the possibility of using the .pc file and the library from different locations.)

You can find the complete source code that implements this approach with the help of libpkg-config in pkgconfig.hxx and pkgconfig-libpkg-config.cxx.

version 0.1.1
license ISC
repository https://pkg.cppget.org/1/alpha
download libpkg-config-0.1.1.tar.gz
sha256 10dd8e9f175ee4295c4ef299caa820bc680fccaee756b469b1dd14458018f00d
project libpkg-config
url github.com/build2/libpkg-config
topics pkg-configlibrarybuild system

Reviews

fail 0
pass 1

Builds

toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-gcc_14-O3
timestamp 2025-08-23 11:29:02 UTC (29 seconds ago)
result error (update) | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-gcc_14-static_O3
timestamp 2025-08-23 11:28:55 UTC (36 seconds ago)
result error (update) | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-gcc_14-ndebug_O3
timestamp 2025-08-23 11:28:13 UTC (01:18 minutes ago)
result error (update) | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-gcc_14
timestamp 2025-08-23 11:27:04 UTC (02:27 minutes ago)
result error (update) | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-gcc_12-relocatable
timestamp 2025-08-23 11:20:57 UTC (08:34 minutes ago)
result error (bindist) | log | rebuild
toolchain public-0.17.0
target x86_64-w64-mingw32
tgt config windows_10-gcc_13.2_mingw_w64-O2
timestamp 2025-08-22 20:00:15 UTC (15:29:16 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-w64-mingw32
tgt config windows_10-gcc_13.2_mingw_w64-static_O2
timestamp 2025-08-22 19:59:48 UTC (15:29:43 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-w64-mingw32
tgt config windows_10-gcc_13.2_mingw_w64
timestamp 2025-08-22 19:58:22 UTC (15:31:10 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-w64-mingw32
tgt config windows_10-gcc_13.2_mingw_w64-relocatable
timestamp 2025-08-22 19:57:33 UTC (15:31:58 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-microsoft-win32-msvc14.3
tgt config windows_10-msvc_17.10-O2
timestamp 2025-08-22 19:56:15 UTC (15:33:17 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-microsoft-win32-msvc14.3
tgt config windows_10-clang_18_llvm_msvc_17.10-static_O2
timestamp 2025-08-22 19:56:04 UTC (15:33:27 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-microsoft-win32-msvc14.3
tgt config windows_10-msvc_17.8-static_O2
timestamp 2025-08-22 19:55:42 UTC (15:33:49 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-microsoft-win32-msvc14.3
tgt config windows_10-clang_18_llvm_msvc_17.10-O2
timestamp 2025-08-22 19:55:29 UTC (15:34:02 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-microsoft-win32-msvc14.3
tgt config windows_10-msvc_17.10-static_O2
timestamp 2025-08-22 19:55:26 UTC (15:34:06 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-microsoft-win32-msvc14.3
tgt config windows_10-clang_18_llvm_msvc_17.10
timestamp 2025-08-22 19:54:38 UTC (15:34:53 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-microsoft-win32-msvc14.3
tgt config windows_10-msvc_17.8-O2
timestamp 2025-08-22 19:54:24 UTC (15:35:07 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-microsoft-win32-msvc14.3
tgt config windows_10-msvc_17.8-relocatable
timestamp 2025-08-22 19:53:54 UTC (15:35:37 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-microsoft-win32-msvc14.3
tgt config windows_10-msvc_17.10
timestamp 2025-08-22 19:53:15 UTC (15:36:16 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-microsoft-win32-msvc14.3
tgt config windows_10-msvc_17.8
timestamp 2025-08-22 19:52:44 UTC (15:36:47 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-microsoft-win32-msvc14.3
tgt config windows_10-clang_17_msvc_msvc_17.10
timestamp 2025-08-22 19:52:42 UTC (15:36:49 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-microsoft-win32-msvc14.3
tgt config windows_10-msvc_17.8-bindist
timestamp 2025-08-22 19:52:20 UTC (15:37:12 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_ubuntu_24.04-gcc_13-bindist
timestamp 2025-08-22 19:50:37 UTC (15:38:54 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-gcc_12-bindist
timestamp 2025-08-22 19:46:46 UTC (15:42:46 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-freebsd13.3
tgt config freebsd_13-clang_17
timestamp 2025-08-22 19:32:02 UTC (15:57:29 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-freebsd14.1
tgt config freebsd_14-clang_18-static_O3
timestamp 2025-08-22 19:24:53 UTC (16:04:39 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-freebsd14.1
tgt config freebsd_14-clang_18-O3
timestamp 2025-08-22 19:23:50 UTC (16:05:41 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-freebsd14.1
tgt config freebsd_14-clang_18
timestamp 2025-08-22 19:22:57 UTC (16:06:34 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-clang_17_libc++
timestamp 2025-08-22 19:22:09 UTC (16:07:22 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-gcc_13.1
timestamp 2025-08-22 19:20:12 UTC (16:09:19 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-clang_17
timestamp 2025-08-22 19:18:40 UTC (16:10:52 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target aarch64-linux-gnu
tgt config linux_debian_12-clang_17_libc++
timestamp 2025-08-22 12:06:44 UTC (23:22:47 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target aarch64-linux-gnu
tgt config linux_debian_12-clang_17
timestamp 2025-08-22 12:05:59 UTC (23:23:32 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target aarch64-linux-gnu
tgt config linux_debian_12-gcc_13
timestamp 2025-08-22 12:05:20 UTC (23:24:12 hours ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_fedora_40-gcc_14-bindist
timestamp 2025-08-22 04:09:22 UTC (01 07:20:09 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-microsoft-win32-msvc14.2
tgt config windows_10_devmode-msvc_16.11
timestamp 2025-08-22 03:51:18 UTC (01 07:38:13 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-microsoft-win32-msvc14.3
tgt config windows_10-clang_14.0_llvm_msvc_17.2_lld
timestamp 2025-08-22 03:40:32 UTC (01 07:48:59 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-microsoft-win32-msvc14.2
tgt config windows_10-msvc_16.11
timestamp 2025-08-22 03:39:41 UTC (01 07:49:50 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-microsoft-win32-msvc14.0
tgt config windows_10-msvc_14.3
timestamp 2025-08-22 03:39:24 UTC (01 07:50:07 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-microsoft-win32-msvc14.1
tgt config windows_10-msvc_15.9
timestamp 2025-08-22 03:38:59 UTC (01 07:50:32 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_9-clang_8.0_libc++
timestamp 2025-08-22 03:23:37 UTC (01 08:05:55 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_ubuntu_22.04-gcc_11-bindist
timestamp 2025-08-22 03:23:17 UTC (01 08:06:14 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_9-gcc_8.4
timestamp 2025-08-22 03:22:57 UTC (01 08:06:35 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_9-clang_7.0_libc++
timestamp 2025-08-22 03:22:41 UTC (01 08:06:50 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_9-clang_6.0_libc++
timestamp 2025-08-22 03:22:33 UTC (01 08:06:59 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-clang_16.0_libc++
timestamp 2025-08-22 03:22:17 UTC (01 08:07:15 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_9-gcc_7.4
timestamp 2025-08-22 03:21:59 UTC (01 08:07:33 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_9-clang_8.0
timestamp 2025-08-22 03:21:38 UTC (01 08:07:53 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-clang_15.0_libc++
timestamp 2025-08-22 03:21:19 UTC (01 08:08:12 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_9-clang_7.0
timestamp 2025-08-22 03:20:58 UTC (01 08:08:33 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_9-clang_6.0
timestamp 2025-08-22 03:20:41 UTC (01 08:08:50 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_8-gcc_4.9
timestamp 2025-08-22 03:20:18 UTC (01 08:09:13 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-clang_16.0
timestamp 2025-08-22 03:20:03 UTC (01 08:09:28 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_11-clang_14.0_libc++
timestamp 2025-08-22 03:19:49 UTC (01 08:09:42 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_10-clang_9.0_libc++
timestamp 2025-08-22 03:19:39 UTC (01 08:09:53 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_11-clang_13.0_libc++
timestamp 2025-08-22 03:19:13 UTC (01 08:10:18 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-clang_15.0
timestamp 2025-08-22 03:18:58 UTC (01 08:10:33 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_10-clang_12.0_libc++
timestamp 2025-08-22 03:18:24 UTC (01 08:11:07 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_10-clang_11.0_libc++
timestamp 2025-08-22 03:17:52 UTC (01 08:11:40 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_11-gcc_11.3
timestamp 2025-08-22 03:17:36 UTC (01 08:11:56 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_11-clang_14.0
timestamp 2025-08-22 03:17:10 UTC (01 08:12:21 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_10-clang_10.0_libc++
timestamp 2025-08-22 03:16:59 UTC (01 08:12:32 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_11-gcc_10.2-bindist
timestamp 2025-08-22 03:16:33 UTC (01 08:12:58 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_10-gcc_10.2
timestamp 2025-08-22 03:16:19 UTC (01 08:13:12 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_10-clang_9.0
timestamp 2025-08-22 03:15:55 UTC (01 08:13:36 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_10-clang_12.0
timestamp 2025-08-22 03:15:23 UTC (01 08:14:08 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_10-clang_11.0
timestamp 2025-08-22 03:14:43 UTC (01 08:14:48 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_10-clang_10.0
timestamp 2025-08-22 03:14:30 UTC (01 08:15:02 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_11-clang_13.0
timestamp 2025-08-22 03:14:18 UTC (01 08:15:13 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_rhel_9-gcc_11-bindist
timestamp 2025-08-21 12:22:42 UTC (01 23:06:49 days ago)
result success | log | rebuild
toolchain public-0.17.0
target aarch64-linux-gnu
tgt config linux_debian_12-clang_18_libc++-O3
timestamp 2025-08-21 03:09:17 UTC (02 08:20:14 days ago)
result success | log | rebuild
toolchain public-0.17.0
target aarch64-linux-gnu
tgt config linux_debian_12-clang_18_libc++-static_O3
timestamp 2025-08-21 03:07:47 UTC (02 08:21:45 days ago)
result success | log | rebuild
toolchain public-0.17.0
target aarch64-linux-gnu
tgt config linux_debian_12-clang_18-O3
timestamp 2025-08-21 03:06:58 UTC (02 08:22:33 days ago)
result success | log | rebuild
toolchain public-0.17.0
target aarch64-linux-gnu
tgt config linux_debian_12-clang_18-static_O3
timestamp 2025-08-21 03:06:31 UTC (02 08:23:00 days ago)
result success | log | rebuild
toolchain public-0.17.0
target aarch64-linux-gnu
tgt config linux_debian_12-clang_18
timestamp 2025-08-21 03:05:48 UTC (02 08:23:43 days ago)
result success | log | rebuild
toolchain public-0.17.0
target aarch64-linux-gnu
tgt config linux_debian_12-clang_18_libc++
timestamp 2025-08-21 03:05:40 UTC (02 08:23:52 days ago)
result success | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_rhel_8-gcc_8-bindist
timestamp 2025-08-20 16:10:23 UTC (02 19:19:09 days ago)
result success | log | rebuild
toolchain public-0.17.0
target aarch64-linux-gnu
tgt config linux_debian_12-gcc_14-ndebug_O3
timestamp 2025-08-20 11:43:56 UTC (02 23:45:35 days ago)
result error (update) | log | rebuild
toolchain public-0.17.0
target aarch64-linux-gnu
tgt config linux_debian_12-gcc_14-static_O3
timestamp 2025-08-20 11:43:16 UTC (02 23:46:15 days ago)
result error (update) | log | rebuild
toolchain public-0.17.0
target x86_64-freebsd14.1
tgt config freebsd_14-clang_18-relocatable
timestamp 2025-08-20 11:43:13 UTC (02 23:46:18 days ago)
result error (bindist) | log | rebuild
toolchain public-0.17.0
target aarch64-linux-gnu
tgt config linux_debian_12-gcc_14
timestamp 2025-08-20 11:41:32 UTC (02 23:48:00 days ago)
result error (update) | log | rebuild
toolchain public-0.17.0
target aarch64-linux-gnu
tgt config linux_debian_12-gcc_14-O3
timestamp 2025-08-20 11:40:48 UTC (02 23:48:44 days ago)
result error (update) | log | rebuild
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_10-gcc_9.3
result unbuilt
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_11-gcc_12.1
result unbuilt
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-clang_18
result unbuilt
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-clang_18-O3
result unbuilt
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-clang_18-static_O3
result unbuilt
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-clang_18_libc++
result unbuilt
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-clang_18_libc++-O3
result unbuilt
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_debian_12-clang_18_libc++-static_O3
result unbuilt
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_fedora_39-gcc_13-bindist
result unbuilt
toolchain public-0.17.0
target x86_64-linux-gnu
tgt config linux_ubuntu_16.04-clang_3.7_libc++
result unbuilt
toolchain public-0.17.0
target x86_64-apple-darwin22.5.0
tgt config macos_13-clang_15.0
result unbuilt
toolchain public-0.17.0
target x86_64-apple-darwin22.5.0
tgt config macos_13-clang_15.0-bindist
result unbuilt
toolchain public-0.17.0
target x86_64-apple-darwin23.5.0
tgt config macos_14-clang_15.0
result unbuilt
toolchain public-0.17.0
target x86_64-apple-darwin23.5.0
tgt config macos_14-clang_15.0-O3
result unbuilt
toolchain public-0.17.0
target x86_64-apple-darwin23.5.0
tgt config macos_14-clang_15.0-relocatable
result unbuilt
toolchain public-0.17.0
target x86_64-apple-darwin23.5.0
tgt config macos_14-clang_15.0-static_O3
result unbuilt
toolchain public-0.17.0
target x86_64-apple-darwin23.5.0
tgt config macos_14-gcc_14_homebrew
result unbuilt
toolchain public-0.17.0
target x86_64-apple-darwin23.5.0
tgt config macos_14-gcc_14_homebrew-O3
result unbuilt
toolchain public-0.17.0
target x86_64-apple-darwin23.5.0
tgt config macos_14-gcc_14_homebrew-static_O3
result unbuilt