#Cross compile OSX to Linux (Ubuntu x84_64)

3 messages · Page 1 of 1 (latest)

gaunt pawn
#

How do I build from OSX to Linux (ubuntu)?
I tried

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

Results in this error error: linking with "cc" failed: exit status: 1

magic rose
#

You're probably getting that error because some of the rust libs rely on external C libraries that they need to link against. An example on how to get it working on macOS is to install the toolchains for cross-compiling.

Note that the snippets and some of the instructions are musl-specific, but I hope they set you on the right path at least! FWIW, I think that setting it up for gnu libc might be less hassle than musl lol

Install the toolchains for the platforms you want to support:

(you'll need to find an alternative way to install your toolchains)

brew install FiloSottile/musl-cross/musl-cross

and then reinstall it (for this specific bottle, it's required because it complains about the --with-aarch64 flag being unrecognised when running with install) with any of the targets you need

brew reinstall FiloSottile/musl-cross/musl-cross --with-aarch64

Then add this to your .cargo/config.toml (adjust your targets as necessary):

[target.x86_64-unknown-linux-musl]
linker = "/opt/homebrew/bin/x86_64-linux-musl-gcc"

[target.aarch64-unknown-linux-musl]
linker = "/opt/homebrew/bin/aarch64-linux-musl-gcc"
hoary frigate
#

You could use cross to build in docker, but there is know issue that mounting from macos to docker is pretty slow to build.