Skip to content

Use pkg-config to detect libnl header and library paths #1698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 15, 2025

Conversation

Explorer09
Copy link
Contributor

Supersedes #1637. Fixes #1639.

@BenBE BenBE requested a review from Copilot May 11, 2025 10:02
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances library detection for libnl by using pkg‑config to determine header and library paths.

  • Updates dlopen calls in LibNl.c to prepend LIBNL3_LIBDIR for both libnl‑3 and libnl‑genl‑3 libraries.
  • Introduces a new function htop_try_link_libnl3 and integrates pkg‑config checks in configure.ac to correctly set the LIBNL3_LIBDIR and CFLAGS.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
linux/LibNl.c Updated dynamic loading calls to prepend LIBNL3_LIBDIR, ensuring the correct library search path is used
configure.ac Added htop_try_link_libnl3 and pkg‑config-based logic to set up library and header search paths for libnl‑3

@BenBE BenBE added enhancement Extension or improvement to existing feature build system 🔧 Affects the build system rather then the user experience labels May 11, 2025
@Explorer09 Explorer09 force-pushed the pkgconfig-libnl branch 3 times, most recently from 117265b to eae13bf Compare May 12, 2025 15:08
Explorer09 and others added 5 commits May 15, 2025 01:37
It no longer requires pkg-config to detect libnl, as the library is now
loaded using dlopen(3) (since
commit 24b1513).
The delay accounting feature ('--enable-delayacct') should be enabled
only if ALL of the netlink/* headers are detected during configure.
The current logic has an error that may set enable_delayacct=yes when
netlink/handlers.h is not found but netlink/msg.h is found.
Fix the logic.

Signed-off-by: Kang-Che Sung <[email protected]>
The libnl3 header search paths may be specified as '-I' options in
"libnl-3.0.pc" cflags. This patch can now detect it automatically.
The user may set the LIBNL3_CFLAGS environment variable to override
pkg-config detection during build.
If pkg-config is not available, a default include path
"/usr/include/libnl3" will be used.

Signed-off-by: Kang-Che Sung <[email protected]>
Introduce LIBNL3_LIBDIR configure variable and preprocessor token to
specify a custom path for loading libnl-3 and libnl-genl-3 using
dlopen(3). This is helpful when libnl packages are installed in a
location outside the default search paths of the libraries.
Gentoo and NixOS need this feature to build.

User may specify LIBNL3_LIBDIR manually during configure. If it's not
specified, configure will try the following in order:
(1) find whether libnl exists within the default library search paths
    by try linking it (LIBNL3_LIBDIR being empty),
(2) locate the 'libdir' value of libnl-3.0 package through pkg-config
    and try linking with the directory included, and
(3) if both fail, go back to the default search paths (LIBNL3_LIBDIR
    being empty) and assume the library doesn't exist during the build
    but will exist at htop runtime.

Co-authored-by: Franz Pletz <[email protected]>
Signed-off-by: Kang-Che Sung <[email protected]>
@BenBE BenBE merged commit 36ea1ef into htop-dev:main May 15, 2025
19 checks passed
@Explorer09 Explorer09 deleted the pkgconfig-libnl branch May 15, 2025 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build system 🔧 Affects the build system rather then the user experience enhancement Extension or improvement to existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression in libnl3 detection (no longer uses pkg-config)
2 participants