Skip to content

CMake: fixes building with LLD in BINARY_LINK_TYPE=dynamic mode - #2714

Open
kraj wants to merge 3 commits into
fastfetch-cli:devfrom
kraj:lld-build-fixes
Open

kraj wants to merge 3 commits into
fastfetch-cli:devfrom
kraj:lld-build-fixes

Conversation

@kraj

@kraj kraj commented Nov 12, 2026

Copy link
Copy Markdown

Summary

Building with -DBINARY_LINK_TYPE=dynamic fails when the linker is LLD (e.g. a clang/LLD cross toolchain in Yocto/OpenEmbedded).

-Wl,--copy-dt-needed-entries is added to CMAKE_EXE_LINKER_FLAGS before the configure checks run. LLD does not implement that option, so every check that links fails (utmpx.h, glob, wordexp, pthread_timedjoin_np, ...) and the features are silently disabled. Once utmpx.h is reported missing, the utmp.h fallback in users_linux.c fails to compile:

src/detection/users/users_linux.c:189:5: error: use of undeclared identifier 'endutxent'; did you mean 'endutent'?

Even with the flag dropped, the final link then fails because fastfetch calls libxcb and libX11 directly but only links xcb-randr/xrandr, which carry them in Requires.private:

ld.lld: error: undefined symbol: xcb_connect
ld.lld: error: undefined symbol: XOpenDisplay

Related issue (required for new logos for new distros)

None

Changes

  • CMake: adds --copy-dt-needed-entries only if check_linker_flag reports the linker accepts it
  • Users (Linux): maps endutxent to endutent in the utmp.h fallback
  • CMake: links libxcb and libX11 explicitly when not using dlopen
  • CHANGELOG entries under Unreleased / Bugfixes

Screenshots

N/A

Checklist

  • I have tested my changes locally.

Tested on Arch Linux x86_64 with clang and -DBINARY_LINK_TYPE=dynamic:

  • -fuse-ld=lld: configure checks pass (HAVE_UTMPX, HAVE_WORDEXP, ...), links, ctest 20/20 passed, Users/Display/OpenGL modules work
  • -fuse-ld=bfd: flag still detected and used, builds and runs as before
  • forced -DHAVE_UTMPX=0: the utmp.h fallback compiles and the Users module works
  • Yocto cross build (x86-64, clang + LLD) of 2.71.0 with these patches builds

kraj added 3 commits November 11, 2026 17:53
LLD does not implement --copy-dt-needed-entries. With
BINARY_LINK_TYPE=dynamic the flag is added to CMAKE_EXE_LINKER_FLAGS
before the configure checks run, so with LLD every check that links
(utmpx.h, glob, wordexp, pthread_timedjoin_np, ...) fails and fastfetch
is built with those features silently disabled.

Check that the linker accepts the flag before adding it.

Signed-off-by: Khem Raj <raj.khem@gmail.com>
The utmp.h fallback maps setutxent and getutxent but not endutxent,
which is called unconditionally, so the build fails with:

error: use of undeclared identifier 'endutxent'; did you mean 'endutent'?
Signed-off-by: Khem Raj <raj.khem@gmail.com>
fastfetch calls libxcb and libX11 functions directly, but only links
xcb-randr and xrandr, whose pkg-config files list the core libraries in
Requires.private. GNU ld resolves them through
--copy-dt-needed-entries; LLD has no such option and fails with
undefined symbols such as xcb_connect and XOpenDisplay.

Link libxcb and libX11 explicitly in the dynamic and static link modes.

Signed-off-by: Khem Raj <raj.khem@gmail.com>
Comment thread CMakeLists.txt
message(STATUS "Enabling custom link type: ${BINARY_LINK_TYPE}")
target_compile_definitions(libfastfetch PUBLIC FF_DISABLE_DLOPEN=1)
if(NOT WIN32)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--copy-dt-needed-entries")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is for xcb and x11

Comment thread CMakeLists.txt
target_link_directories(libfastfetch PRIVATE ${X11_LIBRARY_DIRS})
target_link_libraries(libfastfetch PRIVATE ${X11_LIBRARIES})
endif()
endif()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

-Wl,--copy-dt-needed-entries is unnecessary if you add this.

@CarterLi

Copy link
Copy Markdown
Member

Why do you want to use -DBINARY_LINK_TYPE=dynamic? It's undocumented and not supported, and may be removed at any time.

@tafilz

tafilz commented Nov 12, 2026

Copy link
Copy Markdown

Why do you want to use -DBINARY_LINK_TYPE=dynamic? It's undocumented and not supported, and may be removed at any time.

Hi,

I added the fastfetch recipe to meta-oe for use in Yocto/OpenEmbedded and keep it up-to-date. The latest version is on master-next where I switched the link type.

The initial issue was that, for example, enabling the imagemagick packageconfig option in a minimal image did not pull in the required libraries.

I chose to switch to -DBINARY_LINK_TYPE=dynamic so that Yocto can automatically detect the linked libraries and add the corresponding runtime package dependencies.

If dlopen is the preferred approach, I’ll rework the recipe with explicit runtime dependencies.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants