alpine-pkg-glibc icon indicating copy to clipboard operation
alpine-pkg-glibc copied to clipboard

Can't get things to link properly

Open timarnold opened this issue 5 years ago • 3 comments

I'm trying to install a C NATS client (https://libraries.io/github/nats-io/cnats) on my Alpine Linux Docker image. One of their libraries (https://github.com/nats-io/nats.c/blob/master/pbuf/lib/linux/libprotobuf-c.so) links to libc.so.6, and so I followed the instructions for this project to install glibc.

Once I follow the instructions, I still get linker errors. Random facts that may be helpful:

  • I see libc.so.6 in /usr/lib/libc.so.6 (though it simply seems to be a symbolic link to /lib/ld-musl-x86_64.so.1 - is this expected?)
  • Running ldd /path/to/libprotobuf-c.so shows me:
ldd (0x7fe33e886000)
libc.so.6 => ldd (0x7fe33e886000)

It seems curious to me that libc.so.6 points to ldd instead of, say, /usr/lib/libc.so.6. Is this weird?

  • nm -g /path/to/libprotobuf-c.so yields (excluded irrelevant bits):
U free@@GLIBC_2.2.5
U malloc@@GLIBC_2.2.5
U memcpy@@GLIBC_2.14
U memmove@@GLIBC_2.2.5
U memset@@GLIBC_2.2.5
U strcmp@@GLIBC_2.2.5
U strlen@@GLIBC_2.2.5

and these symbols are the ones I get "undefined reference to" when I try to build.

  • When I run objdump -TC /usr/lib/libc.so.6 and search for these symbols, I see symbols like memset, strcmp, etc., but they don't have the @@GLIBC_ bits. After some searching it seems these are called "version tags" (https://stackoverflow.com/a/41093059/1148702). When I objdump -TC /my/path/to/libc.so.6 on my Ubuntu machine (not Docker), I do see these version tags, so I'm thinking my linker errors have something to do with them being missing on my Alpine Docker build.

Can anyone point me in the right direction?

timarnold avatar May 17 '19 20:05 timarnold

I'm still curious to learn how this works (and why these symbols weren't being found), but I do think I've solved my underlying problem by rebuilding the library in question rather than using this provided prebuilt library that was causing me issues.

timarnold avatar May 20 '19 13:05 timarnold

👋 Alpine Linux uses the musl C library as its libc implementation. I suspect you had the libc6-compat package installed. That's part of the reason for the elements you've observed.

You can see more about how the musl packages are built here: https://git.alpinelinux.org/aports/tree/main/musl/APKBUILD?h=master

sgerrand avatar Jul 25 '19 09:07 sgerrand

This package installs the libc.so* files to /usr/glibc-compat/lib/.

e.g.

# ls -l /usr/glibc-compat/lib/libc*
-rwxr-xr-x    1 root     root       1816304 Feb 11 19:28 /usr/glibc-compat/lib/libc-2.29.so
-rw-r--r--    1 root     root           294 Feb 10 17:26 /usr/glibc-compat/lib/libc.so
lrwxrwxrwx    1 root     root            12 Mar 18 02:04 /usr/glibc-compat/lib/libc.so.6 -> libc-2.29.so

sgerrand avatar Jul 25 '19 09:07 sgerrand