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

Static linking issue with x86_64-unknown-linux-gnu on a linux x86_64 system #381

Open
guenhter opened this issue Jul 28, 2023 · 0 comments

Comments

@guenhter
Copy link

Hi,

I try to statically link my zeromq application but totally failing on this task.
Here my environment narrowed down to the core problem.

docker container run -it --rm rust:1.71.0

cargo init foo
cd foo
cargo add zmq-sys
echo "fn main() { unsafe { zmq_sys::zmq_ctx_new() }; }" > src/main.rs

And when I run this:

RUSTFLAGS='-C target-feature=+crt-static' cargo build --release --target x86_64-unknown-linux-gnu

I get this error:

   ...
   Compiling version-compare v0.1.1
   Compiling zeromq-src v0.2.5+4.3.4
   Compiling toml v0.7.6
   Compiling system-deps v6.1.1
   Compiling zmq-sys v0.12.0
   Compiling foo v0.1.0 (/foo)
error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/usr/local/rustup/toolchains/1.71.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/usr/local/cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" VSLANG="1033" "cc" "-m64" "/tmp/rustc96qgBc/symbols.o" "/foo/target/x86_64-unknown-linux-gnu/release/deps/foo-cb6ba11158d315c4.foo.b2f903485695e401-cgu.0.rcgu.o" "/foo/target/x86_64-unknown-linux-gnu/release/deps/foo-cb6ba11158d315c4.foo.b2f903485695e401-cgu.1.rcgu.o" "/foo/target/x86_64-unknown-linux-gnu/release/deps/foo-cb6ba11158d315c4.foo.b2f903485695e401-cgu.2.rcgu.o" "/foo/target/x86_64-unknown-linux-gnu/release/deps/foo-cb6ba11158d315c4.38dmy2d9chj96ssl.rcgu.o" "-Wl,--as-needed" "-L" "/foo/target/x86_64-unknown-linux-gnu/release/deps" "-L" "/foo/target/release/deps" "-L" "/foo/target/x86_64-unknown-linux-gnu/release/build/zmq-sys-189974278a500c32/out/lib" "-L" "/foo/target/x86_64-unknown-linux-gnu/release/build/zmq-sys-189974278a500c32/out/lib" "-L" "/usr/local/rustup/toolchains/1.71.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/foo/target/x86_64-unknown-linux-gnu/release/deps/libzmq_sys-fc6815d34ec73a41.rlib" "/foo/target/x86_64-unknown-linux-gnu/release/deps/liblibc-25ef17eb55ea3a7e.rlib" "/usr/local/rustup/toolchains/1.71.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-0d91c78a7710ed2e.rlib" "/usr/local/rustup/toolchains/1.71.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-9bfeb974ba4dc4e7.rlib" "/usr/local/rustup/toolchains/1.71.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-7dd2d47ddb5fff81.rlib" "/usr/local/rustup/toolchains/1.71.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-18d5ce8e8a320b85.rlib" "/usr/local/rustup/toolchains/1.71.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-69d2770595dc6161.rlib" "/usr/local/rustup/toolchains/1.71.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-b156a020cc470e38.rlib" "/usr/local/rustup/toolchains/1.71.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-84091f15e468b1ee.rlib" "/usr/local/rustup/toolchains/1.71.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-fbde6acb28b510ca.rlib" "/usr/local/rustup/toolchains/1.71.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-e9de5d8ee4e7a3dd.rlib" "/usr/local/rustup/toolchains/1.71.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-9023252e4f119830.rlib" "/usr/local/rustup/toolchains/1.71.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-fcbb01769e88af40.rlib" "/usr/local/rustup/toolchains/1.71.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-f69e84994e245fea.rlib" "/usr/local/rustup/toolchains/1.71.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-27b55c02caca49ea.rlib" "/usr/local/rustup/toolchains/1.71.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-579b26075cbe9eca.rlib" "/usr/local/rustup/toolchains/1.71.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-54c30397d4b33d3b.rlib" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-lgcc_eh" "-lgcc" "-lc" "/usr/local/rustup/toolchains/1.71.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-65fb576691133eee.rlib" "/usr/local/rustup/toolchains/1.71.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-3fff6412017c0b89.rlib" "/usr/local/rustup/toolchains/1.71.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-fd3918c72578db43.rlib" "/usr/local/rustup/toolchains/1.71.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-2a597573799b576f.rlib" "-Wl,-Bdynamic" "-lstdc++" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/usr/local/rustup/toolchains/1.71.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/foo/target/x86_64-unknown-linux-gnu/release/deps/foo-cb6ba11158d315c4" "-Wl,--gc-sections" "-static-pie" "-Wl,-z,relro,-z,now" "-Wl,-O1" "-nodefaultlibs"
  = note: /usr/bin/ld: /usr/local/rustup/toolchains/1.71.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-0d91c78a7710ed2e.rlib(std-0d91c78a7710ed2e.std.a2d7a4c8dd6a1366-cgu.0.rcgu.o): in function `std::sys::unix::os::home_dir::fallback':
          /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/sys/unix/os.rs:642: warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
          /usr/bin/ld: /foo/target/x86_64-unknown-linux-gnu/release/deps/libzmq_sys-fc6815d34ec73a41.rlib(711a6e249c8746d4-ip_resolver.o): in function `zmq::ip_resolver_t::do_getaddrinfo(char const*, char const*, addrinfo const*, addrinfo**) [clone .localalias]':
          ip_resolver.cpp:(.text._ZN3zmq13ip_resolver_t14do_getaddrinfoEPKcS2_PK8addrinfoPPS3_+0xd): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
          /usr/bin/ld: /usr/local/rustup/toolchains/1.71.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-0d91c78a7710ed2e.rlib(std-0d91c78a7710ed2e.std.a2d7a4c8dd6a1366-cgu.0.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)

error: could not compile `foo` (bin "foo") due to previous error

Any idea how this can be solved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant