rustc lib.rs -g --crate-type dylib --target arm-linux-androideabi
fails with the following error, even if lib.rs
is an empty file:
error: linking with `cc` failed: exit code: 1
note: "cc" "-Wl,--as-needed" "-Wl,--allow-multiple-definition" "-L" "/home/mbrubeck/.servo/rust/168a23ebe1729386138fa71643382fdd64fac205/rustc-1.5.0-dev-x86_64-unknown-linux-gnu/rustc/lib/rustlib/arm-linux-androideabi/lib" "lib.0.o" "-o" "liblib.so" "lib.metadata.o" "-nodefaultlibs" "-L" "/home/mbrubeck/.servo/rust/168a23ebe1729386138fa71643382fdd64fac205/rustc-1.5.0-dev-x86_64-unknown-linux-gnu/rustc/lib/rustlib/arm-linux-androideabi/lib" "-L" "/home/mbrubeck/src/image-gif/.rust/lib/arm-linux-androideabi" "-L" "/home/mbrubeck/src/image-gif/lib/arm-linux-androideabi" "-Wl,-Bstatic" "-Wl,-Bdynamic" "-Wl,--whole-archive" "/tmp/rustc.EKTAUblKIJax/libstd-bb943c5a.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.EKTAUblKIJax/libcollections-bb943c5a.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.EKTAUblKIJax/librustc_unicode-bb943c5a.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.EKTAUblKIJax/librand-bb943c5a.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.EKTAUblKIJax/liballoc-bb943c5a.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.EKTAUblKIJax/liballoc_system-bb943c5a.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.EKTAUblKIJax/liblibc-bb943c5a.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.EKTAUblKIJax/libcore-bb943c5a.rlib" "-Wl,--no-whole-archive" "-l" "dl" "-l" "log" "-l" "gcc" "-l" "gcc" "-l" "c" "-l" "m" "-shared" "-l" "compiler-rt"
note: /usr/bin/ld: lib.0.o: Relocations in generic ELF (EM: 40)
lib.0.o: error adding symbols: File in wrong format
collect2: error: ld returned 1 exit status
error: aborting due to previous error
This happens with Servo's current Rust snapshot (rustc 1.5.0-dev (168a23ebe 2015-10-01)) and also with older versions at least as far back as 1.3.0-dev.
This also happens when I try to compile an executable. I suspect something is wrong/missing in my environment... Do I need to set environment variables or pass flags to get rustc to use the correct linker for my target?
I was missing -C linker=arm-linux-androideabi-gcc
. Sorry for the false alarm. Now to figure out why Cargo is not passing this...
For anyone else landing here from a Google search: you can configure the linker in a cargo-config
file in the root of your project:
[target.arm-linux-androideabi]
linker = "arm-linux-androideabi-gcc"
Alternatively, you can also use export CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=/usr/bin/arm-linux-gnueabihf-gcc
(for the arm-linux-gnueabihf
target in this example)
Actually, for me to work, the file needed to be named .cargo/config
(in project root) - is there a way to have that in the Cargo.toml?
Most helpful comment
For anyone else landing here from a Google search: you can configure the linker in a
cargo-config
file in the root of your project: