Rustup: Targeting x86_64-apple-darwin on Linux yields linking errors

Created on 14 May 2016  路  4Comments  路  Source: rust-lang/rustup

Targeting x86_64-apple-darwin on Linux yields linking errors.

source.0.o: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status

To reproduce :

From this Docker container: https://gist.github.com/netgusto/77a8faaa8bf348468c7e6193cba529b6

$ cd /source
$ rustup target add x86_64-apple-darwin
$ cargo init --bin
$ cargo build --target=x86_64-apple-darwin

   Compiling source v0.1.0 (file:///source)
error: linking with `cc` failed: exit code: 1
note: "cc" "-m64" "-L" "/root/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib" "/source/target/x86_64-apple-darwin/debug/source.0.o" "-o" "/source/target/x86_64-apple-darwin/debug/source" "-Wl,-dead_strip" "-nodefaultlibs" "-L" "/source/target/x86_64-apple-darwin/debug" "-L" "/source/target/x86_64-apple-darwin/debug/deps" "-L" "/root/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib" "/root/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/libstd-4fda350b.rlib" "/root/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/libcollections-4fda350b.rlib" "/root/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/librustc_unicode-4fda350b.rlib" "/root/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/librand-4fda350b.rlib" "/root/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/liballoc-4fda350b.rlib" "/root/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/liballoc_jemalloc-4fda350b.rlib" "/root/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/liblibc-4fda350b.rlib" "/root/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-apple-darwin/lib/libcore-4fda350b.rlib" "-l" "System" "-l" "pthread" "-l" "c" "-l" "m" "-l" "compiler-rt"
note: /source/target/x86_64-apple-darwin/debug/source.0.o: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status

error: aborting due to previous error

Could not compile `source`.

Environment:

$ uname -a
Linux bd1bb678d87a 4.4.9-moby #1 SMP Tue May 10 10:36:54 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
$ rustc --version
rustc 1.8.0 (db2939409 2016-04-11)
$ rustup --version
rustup 0.1.12 (c6e430a 2016-05-12)

Most helpful comment

The Go toolchain supports compiling and linking Linux, Mac, and Windows targets from any and to any of these hosts. Could rustup get something similar, to make build bots easier to setup?

All 4 comments

You'll at the very least need a linker capable of linking Mach-O files. rustup makes it easy to get pre-compiled versions of std for your target platform, but you still need a linker and potentially a C compiler which also target that platform, along with any platform-specific libraries that need to be linked in.

If anyone has a procedure to make it compile, please share it ! Otherwise, I guess this can be closed.

Since there's no practical solution to this on the horizon, and it's similar to other cross-compile scenarios, I'm going to close this. Thanks for the report.

The Go toolchain supports compiling and linking Linux, Mac, and Windows targets from any and to any of these hosts. Could rustup get something similar, to make build bots easier to setup?

Was this page helpful?
0 / 5 - 0 ratings