1

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.

Jon Koenig
  • 53
  • 7
  • 2
    You might need a VM, or to use ports instead of brew. binutils on brew doesn't include the linker. See also [this](https://stackoverflow.com/a/1618671/5774952) which is old, but I think still correct. – Zac Anger May 03 '23 at 20:10

1 Answers1

0

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"
haohaolee
  • 677
  • 1
  • 9
  • 16
  • The reason why your config does not work is because gcc is not a cross compiler by default, as well as its linker, so it doesn't understand what `x86_64-unknown-linux-gnu` is – haohaolee May 20 '23 at 02:23