rust-libxml
rust-libxml copied to clipboard
Not able to link statically
When passing -C target-feature=+crt-static
to the Rust compiler for the target x86_64-unknown-linux-gnu
, the following error appears at linking:
= note: /usr/bin/ld: /home/temrix/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-89bc084783fdc439.rlib(std-89bc084783fdc439.std.5f6d52e5-cgu.0.rcgu.o): in function `std::sys::unix::os::home_dir::fallback':
/rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys/unix/os.rs:638: warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /home/temrix/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-89bc084783fdc439.rlib(std-89bc084783fdc439.std.5f6d52e5-cgu.0.rcgu.o): in function `<std::sys_common::net::LookupHost as core::convert::TryFrom<(&str,u16)>>::try_from::{{closure}}':
/rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/net.rs:207: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /home/temrix/Dokumente/coding/my-project/target/x86_64-unknown-linux-gnu/debug/deps/libreqwest-e9d0c520f0b95258.rlib(reqwest-e9d0c520f0b95258.reqwest.32e49cb3-cgu.13.rcgu.o): undefined reference to symbol '__tls_get_addr@@GLIBC_2.3'
/usr/bin/ld: /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2: error adding symbols: DSO missing from command line
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)
It cannot link libxml. If I try without it, everything goes well and I can execute the binary.
I also tried to build it under Alpine, which resulted in a segfault when executing.
Is there anything I can do to compile with libxml statically?
I don't know the answer, so I would have to do some further digging to see what the details are exactly. This is the first time static linking has raised for this wrapper crate.
I keep hoping that we will have a c2rust variant of libxml2 that allows us to be fully Rust-native (and will avoid the dependency entirely), but that is probably still some ways away.