Yixing Liu
Yixing Liu

Reputation: 2429

Alternative solutions to missing shared libraries after cross compilation?

I first cross compile my Rust project to linux target

cargo build --target x86_64-unknown-linux-gnu

Then run ldd on my local ubuntu and the linker works fine.

linux-vdso.so.1 (0x00007fffddc62000)
libssl.so.1.0.0 => /usr/lib/x86_64-linux-gnu/libssl.so.1.0.0 (0x00007f6d34500000)
libcrypto.so.1.0.0 => /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f6d340b0000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f6d33ea0000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f6d33c90000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f6d33a70000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f6d33850000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6d33440000)
/lib64/ld-linux-x86-64.so.2 (0x00007f6d35a00000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f6d330a0000)

But on my target os, ldd fails to find the libraries

libssl.so.1.0.0 => not found
libcrypto.so.1.0.0 => not found
/lib64/libc.so.6 => version `GLIBC_2.18' not found

Actually I have libssl.so.10 and libcrypto.so.10 installed under LD_LIBRARY_PATH. Unfortunately I am not able to install shared libraries of version 1.0.0 required by Rust.

I have read Rust Cross and the recommended solution is to install the missing shared libraries. Unfortunately that's not possible for me. So I am looking for alternative solutions to missing libraries.

libssl.so.1.0.0 and libcrypto.so.1.0.0 sound ancient. How can I tell cargo to use a later version?

How can I deal with /lib64/libc.so.6 => version GLIBC_2.18 not found?

Upvotes: 0

Views: 1468

Answers (1)

Yixing Liu
Yixing Liu

Reputation: 2429

According to this, GLIBC_2.18 can't be installed to RHEL7. I gave up dynamically linked libraries.

This post helped me out. The solution is:

[dependencies]
nats = "*"
protobuf = { version = "~2.0" }
# Add openssl-sys as a direct dependency so it can be cross compiled to
# x86_64-unknown-linux-musl using the "vendored" feature below
openssl-sys = "*"

[features]
# Force openssl-sys to staticly link in the openssl library. Necessary when
# cross compiling to x86_64-unknown-linux-musl.
vendored = ["openssl-sys/vendored"]

This way I can compile to a single executable with no library dependencies using:

cargo build --target=x86_64-unknown-linux-musl --features vendored

Upvotes: 2

Related Questions