Cross compile from ARM macOS to Linux?

1k Views Asked by At

I'm having some trouble getting my compilation from apple silicon -> x86 linux working. I'm compiling with this command:

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

I have these targets installed:

aarch64-apple-darwin (installed)
x86_64-apple-darwin (installed)
x86_64-pc-windows-gnu (installed)
x86_64-unknown-linux-gnu (installed)

I'm using gcc from homebrew (brew install gcc) and I have this .cargo/config file:

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

I'm getting this output:

error: linking with `/opt/homebrew/bin/gcc-13` failed: exit status: 1
= note: ld: unknown option: --as-needed
          collect2: error: ld returned 1 exit status

Can anyone see anything obvious wrong with my configuration?

Thanks.

1

There are 1 best solutions below

1
haohaolee On

I haven't gave the following a try on my machine, but you can install and try zig:

[target.x86_64-unknown-linux-gnu]
linker = "zig cc -target x86_64-unknown-linux-gnu"