Is possible to specify the gcc version while compiling?

I want to compile a binary for ubuntu on my archlinux.

But ubuntu's GCC is older than archlinux's.

When I execute the binary, it will report libc.x not found.

Is it possible to build this binary with an older GCC version on my archlinux.

You could install another gcc version from the AUR. And then use that.
But I don't think you can have multiple versions of libc on your machines normal shared library path. It is possible to use a different libc, there are GCC flags for it.

You could also make a static binary, that way you are not dependent on system libc.

The easiest way to take care of this for Rust code is to produce a statically-compiled executable using the musl target. If your crate also depends on C code, you can use the rust-musl-builder Docker image.

2 Likes

Unfortunately, it contains some c++ code like the librocksdb-sys.

IIUC, that can't be compiled into a musl target.

You should look at crosstool-NG to produce a standalone toolchain using a specific version of the libc and still with a recent GCC. You would be able to target older distributions while being able to build projects requiring recent compiler (depending on C++17/20 features for example).

It seems that the guys behind cross (so this sounds like a very reliable soluion here :wink: ) already provide this kind of facility to use this for Rust toolchain: https://github.com/cross-rs/cross-toolchains

I found this while looking if something exists to easily integrate this into Rust toolchain and I should have a look at it myself as it can help me reduce the burden to manage this kind of toolchains :slight_smile:

... or you can simply cross-build it using cross if their build image already targets an old enough version of libc.