Sassa
Sassa

Reputation: 2023

How can I make my Rust program link to another glibc?

I have a crosstool-ng toolchain for i686-linux-unknown-gnu, this toolchain contains a different glibc than the one installed in my host.

The path to my libc.so.6 is:

~/x-tools/i686-unknown-linux-gnu/i686-unknown-linux-gnu/sysroot/lib

How can I tell Cargo to link to the glibc located in this directory instead of the system one?

I have already tried LD_LIBRARY_PATH, but it doesn't work.

What works is to set in my .cargo/config file this:

[target.i686-unknown-linux-gnu]
linker = "i686-unknown-linux-gnu-gcc"

But that links my program with the GCC toolchain instead of Clang. I want to use Clang and just link against a different glibc.

Upvotes: 4

Views: 2223

Answers (1)

Sassa
Sassa

Reputation: 2023

As kennytm pointed out, I can use .cargo/config to tell where is the new glibc by using the sysroot parameter:

[target.i686-unknown-linux-gnu]
rustflags = ["-C", "link-args=--sysroot=/home/ebarreto/x-tools/i686-unknown-linux-gnu/i686-unknown-linux-gnu/sysroot"]

The --sysroot parameter will contain the path to my sysroot where lies the custom glibc.

I still think this is not the most practical way to do that, but I don't know a better way..

Upvotes: 3

Related Questions