nagisa / rust_libloading

Bindings around the platform's dynamic library loading primitives with greatly improved memory safety.

Home Page:https://docs.rs/libloading

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Linking against musl fails

jean-airoldie opened this issue · comments

Issue Description

Running the tests on the master branch fails with a linking error when using musl:

$ cargo test --target "x86_64-unknown-linux-musl"
error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/home/maxence/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown [...] massive command that I skipped for brevity
  = note: /usr/bin/ld: /home/maxence/clone/rust_libloading/target/x86_64-unknown-linux-musl/debug/deps/functions-9b016fe89b2bccc1.1il6biux58wlp61n.rcgu.o: in function `libloading::os::unix::Library::open::{{closure}}':
          /home/maxence/clone/rust_libloading/src/os/unix/mod.rs:173: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
          /usr/bin/ld: /home/maxence/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/libc.a(dlerror.lo): in function `__get_tp':
          /build/musl-cross-make/build/local/x86_64-linux-musl/obj_musl/../src_musl/arch/x86_64/pthread_arch.h:4: multiple definition of `dlerror'; /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libdl.a(dlerror.o):(.text+0x0): first defined here
          /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libdl.a(dlopen.o): in function `dlopen':
          (.text+0x5): undefined reference to `__dlopen'
          /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libdl.a(dlclose.o): in function `dlclose':
          (.text+0x1): undefined reference to `__dlclose'
          /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libdl.a(dlerror.o): in function `dlerror':
          (.text+0x1): undefined reference to `__dlerror'
          collect2: error: ld returned 1 exit status

  = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)
error: could not compile `libloading` (test "functions") due to 1 previous error

My System

I'm running Debian 11 with kernel version 5.10.0-26-amd64 and all the required packages to build musl. My rust compiler version is 1.76.0-nightly (21cce21d8 2023-12-11).

Related issue rust-windowing/glutin#1651

I suspect you may need to disable feature that statically links the crt, which the musl target enables by default. Something along the lines of -Ctarget-feature=-crt-static,

No, I meant to link against musl statically, but I didn't understand the implications with respect to dlopen. I found this thread that goes into details into how this is possible but very dumb. I guess that makes c runtime static linking out of the question for my use case.