Cross-compiling to x86_64-unknown-linux-gnu fails

When I try to compile some rust code to x86_64-unknown-linux-gnu using cargo build --target x86_64-unknown-linux-gnu, it will always error out with this:

error: linking with `cc` failed: exit status: 1
  |
(a whole bunch of file paths)
  |
 = note: clang: warning: argument unused during compilation: '-pie' [-Wunused-command-line-argument]
          ld: unknown option: --as-needed
          clang: error: linker command failed with exit code 1 (use -v to see invocation)
          

error: could not compile `my-project` due to previous error

What does this mean and how do I fix it?

(from x86_64-apple-darwin to x86_64-unknown-linux-gnu)

You have a macOS-only linker, which doesn't support linking Linux executables. Rust doesn't support cross-compilation out of the box of anything other than static libraries. You need to get a Linux-compatible linker from somewhere, and configure Cargo to use it.

Alternatively, build inside a Docker image:

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.