Skip to content

linking against shared library will fail when subdependency isn't on library path #23849

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

Open
Jan200101 opened this issue May 10, 2025 · 0 comments · May be fixed by #23850
Open

linking against shared library will fail when subdependency isn't on library path #23849

Jan200101 opened this issue May 10, 2025 · 0 comments · May be fixed by #23850
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@Jan200101
Copy link
Contributor

Jan200101 commented May 10, 2025

Zig Version

0.14.0

Steps to Reproduce and Observed Behavior

Found while trying to package ncdu for Fedora

ncdu links against ncursesw which itself links to tinfo and because shared objects only embed the dependency name and not a full path it will attempt to find the library, which it won't succeed with[1].

the full chain of commands goes:

  1. /usr/bin/zig build
  2. /usr/bin/zig build-exe -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 -lncursesw -ltinfo -lzstd -fno-strip -ODebug -Mroot=/home/sentry/git/ncdu/src/main.zig -lc --cache-dir /home/sentry/git/ncdu/.zig-cache --global-cache-dir /home/sentry/.cache/zig --name ncdu --zig-lib-dir /usr/lib/zig/ --listen=-
  3. ld.lld --error-limit=0 -mllvm -float-abi=hard --entry _start -z stack-size=16777216 --image-base=16777216 --eh-frame-hdr -znow -m elf_x86_64 -o ncdu /home/sentry/.cache/zig/o/e6af199bb17435a138866251ed3ea3fd/crt1.o -dynamic-linker /lib64/ld-linux-x86-64.so.2 ncdu.o --as-needed /lib64/libncursesw.so /lib64/libtinfo.so /lib64/libzstd.so /home/sentry/.cache/zig/o/31ee13b287dd6a347b524ffe90ce7ffc/libm.so.6 /home/sentry/.cache/zig/o/31ee13b287dd6a347b524ffe90ce7ffc/libc.so.6 /home/sentry/.cache/zig/o/31ee13b287dd6a347b524ffe90ce7ffc/libld.so.2 /home/sentry/.cache/zig/o/31ee13b287dd6a347b524ffe90ce7ffc/libresolv.so.2 /home/sentry/.cache/zig/o/e88f83e50bb73388bec0b5dfa5fa9721/libc_nonshared.a /home/sentry/.cache/zig/o/bb531447702b6bcd68ce0c01e22e5e5d/libcompiler_rt.a[2]

which then errors with > error: ld.lld: unable to find library -ltinfo

  • removing /lib64/libtinfo.so does nothing
  • adding -L /usr/lib64 makes it work
  • removing /lib64/libncursesw.so outputs linker errors due to ncursesw missing, but the library error no longer appears

ldd output of ncursesw

$ ldd /lib64/libncursesw.so.6.5
        linux-vdso.so.1 (0x00007fe59e1e7000)
        libtinfo.so.6 => /lib64/libtinfo.so.6 (0x00007fe59e13c000)
        libc.so.6 => /lib64/libc.so.6 (0x00007fe59df4a000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fe59e1e9000

solutions:

  • get all library paths from pkg-config
    • pkg-config omits system paths automatically but can be instructed to keep them
    • this would still break anything not using pkg-config
  • add the library directories of all linked libraries

[1] Zig will add the libc installation path to the linker paths which is likely to be the normal lib dir masking this issue
[2] the previous command was ran with a stubbed cc binary otherwise it would be adding -L /usr/lib/gcc/x86_64-redhat-linux/15/../../../../lib64

Expected Behavior

zig just work

@Jan200101 Jan200101 added the bug Observed behavior contradicts documented or intended behavior label May 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant