Skip to content
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

Alpine linux can't link to the library installed via apk #2860

Open
wisonye opened this issue Mar 13, 2025 · 5 comments
Open

Alpine linux can't link to the library installed via apk #2860

wisonye opened this issue Mar 13, 2025 · 5 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@wisonye
Copy link

wisonye commented Mar 13, 2025

  1. Install via native apk

    doas apk --no-cache add notcurses notcurses-dev notcurses-doc notcurses-libs notcurses-static notcurses-tetris notcurses-view
  2. Create a hello program, compile and run:

    >>> [ RUN ]
    >>> OS_TYPE: Linux
    >>> BUILD_TYPE: Debug
    >>> STATIC_BUILD: No
    >>> MUSL_LIBC: Yes
    >>> COMMAND: /usr/lib/llvm19/bin/clang
    -std=c23 -Wall -Werror
    -D ENABLE_DEBUG_LOG
    -D_BSD_SOURCE -DNCURSES_WIDECHAR
    -lnotcurses -lnotcurses-core
    -D __MUSL__ -D _GNU_SOURCE
    -g
    -o ./temp_build/main
    src/main.c
    && ./temp_build/main
    # /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/main-9b2484.o: in function `main':
    # /home/wison/c/notcurses-tutorial/c/src/main.c:95:(.text+0x4c): undefined reference to `notcurses_core_init'
    # /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /home/wison/c/notcurses-tutorial/c/src/main.c:96:(.text+0x59): undefined reference to `notcurses_stdplane'
    # /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /home/wison/c/notcurses-tutorial/c/src/main.c:105:(.text+0xcb): undefined reference to `notcurses_stop'
    # /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/main-9b2484.o: in function `ncplane_putstr_yx':
    # /usr/include/notcurses/notcurses.h:2277:(.text+0x136): undefined reference to `ncplane_putegc_yx'
    # /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/main-9b2484.o: in function `notcurses_render':
    # /usr/include/notcurses/notcurses.h:1150:(.text+0x1c1): undefined reference to `notcurses_stdplane'
    # /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/include/notcurses/notcurses.h:1151:(.text+0x1ce): undefined reference to `ncpile_render'
    # /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/include/notcurses/notcurses.h:1154:(.text+0x1e5): undefined reference to `ncpile_rasterize'
    # clang: error: linker command failed with exit code 1 (use -v to see invocation)

    Libraries in the default link path:

    ls -lht /usr/lib/{libnotcurses.so, libnotcurses-core.so}
    
    # lrwxrwxrwx    1 root     root          22 Mar 12 16:04 /usr/lib/libnotcurses-core.so -> libnotcurses-core.so.3*
    # lrwxrwxrwx    1 root     root          17 Mar 12 16:04 /usr/lib/libnotcurses.so -> libnotcurses.so.3*
@wisonye wisonye added the bug Something isn't working label Mar 13, 2025
@dankamongmen dankamongmen self-assigned this Mar 14, 2025
@dankamongmen dankamongmen added this to the 3.1.0 milestone Mar 14, 2025
@dankamongmen
Copy link
Owner

hrmmm, that's worrying

@dankamongmen
Copy link
Owner

is _GNU_SOURCE supposed to be used with -D __MUSL__? just wondering.

@dankamongmen
Copy link
Owner

i will probably need to spin up an alpine VM to look into this. can you verify that the "missing" symbols are present in libnotcurses-core.so using objdump? i'll try to get a VM up shortly.

@wisonye
Copy link
Author

wisonye commented Mar 15, 2025

is _GNU_SOURCE supposed to be used with -D __MUSL__? just wondering.

Oh, it doesn't matter, usually my project HAS to be compiled on MacOS/FreeBSD/AlpineLinux (sometimes another Linux distro, e.g. ArchLinux, dependons on my teammate's needs)

That __MUSL__ is a custom macro to detected whether on MUSL libc or not like this:

set MUSL (ldd /bin/ls | grep 'musl' | head -1 | cut -d ' ' -f1)

# MUSL LIBC
if test -n "$MUSL"
    # set CFLAGS "$CFLAGS -D __MUSL__ -D _GNU_SOURCE\n"
    set CFLAGS "$CFLAGS -D __MUSL__\n"
end

The linking issue still there without _GUN_SOURCE, it's NOT the reason to cause the linking error:)

@wisonye
Copy link
Author

wisonye commented Mar 15, 2025

i will probably need to spin up an alpine VM to look into this. can you verify that the "missing" symbols are present in libnotcurses-core.so using objdump? i'll try to get a VM up shortly.

They're there except ncplane_putstr_yx

 N  wison | /home/wison   objdump -T /usr/lib/libnotcurses.so | rg notcurses
# /usr/lib/libnotcurses.so:     file format elf64-x86-64
# 0000000000000000      DF *UND*  0000000000000000  Base        notcurses_core_init
# 0000000000000000      DF *UND*  0000000000000000  Base        ncplane_notcurses
# 0000000000003740 g    DF .text  0000000000000017  Base        notcurses_init


 I  wison | /home/wison   objdump -T /usr/lib/libnotcurses-core.so | rg \
                                   -e "notcurses_core_init" \
                                   -e "notcurses_stdplane" \
                                   -e "notcurses_stop" \
                                   -e "ncplane_putstr_yx" \
                                   -e "ncplane_putegc_yx" \
                                   -e "ncpile_render" \
                                   -e "ncpile_rasterize"

# 000000000002e7a0 g    DF .text  0000000000000004 notcurses_stdplane
# 0000000000033940 g    DF .text  0000000000000093 ncplane_putegc_yx
# 00000000000350d0 g    DF .text  0000000000000e60 notcurses_core_init
# 000000000002e7b0 g    DF .text  0000000000000004 notcurses_stdplane_const
# 0000000000045c70 g    DF .text  000000000000024b ncpile_render_to_file
# 00000000000478d0 g    DF .text  0000000000000354 ncpile_rasterize
# 0000000000031320 g    DF .text  00000000000002e9 notcurses_stop
# 0000000000045ec0 g    DF .text  0000000000000464 ncpile_render
# 0000000000046330 g    DF .text  00000000000000e6 ncpile_render_to_buffer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants