Issues when linking cross compiled binaries

Hello,

I'm having some issues when cross-compiling a Rust executable from Linux x86_64 to Windows (both i686 and x86_64) and Mac (x86_64 apple-darwin). With Windows, the problem is I get this from the linker:

note: /usr/bin/ld: unrecognized option '--enable-long-section-names'

While compiling for Mac, I get this:

note: /home/razican/workspace/apk-audit/target/x86_64-apple-darwin/release/apk_audit.0.o: file not recognized: File format not recognized

My ld version:

GNU ld version 2.25-17.fc23
  Supported emulations:
   elf_x86_64
   elf32_x86_64
   elf_i386
   i386linux
   elf_l1om
   elf_k1om
1 Like

When you're cross-compiling, you need to specify an appropriate linker; there's a brief discussion of the "linker" option at Taking Rust everywhere with rustup | Rust Blog .

If you're targeting Windows, most distributions provide a mingw package. If you're targeting Mac, you'll have to come up with the right tools yourself; maybe https://github.com/tpoechtrager/osxcross is helpful?

1 Like

Oh, OK, I thought the linker was included with the toolchain, thanks :slight_smile: