Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link error when cross-compiling to ARM with --crate-type dylib: Relocations in generic ELF (EM: 40) #28924

Closed
mbrubeck opened this issue Oct 9, 2015 · 5 comments

Comments

@mbrubeck
Copy link
Contributor

mbrubeck commented Oct 9, 2015

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 (168a23e 2015-10-01)) and also with older versions at least as far back as 1.3.0-dev.

@mbrubeck
Copy link
Contributor Author

mbrubeck commented Oct 9, 2015

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?

@mbrubeck
Copy link
Contributor Author

mbrubeck commented Oct 9, 2015

I was missing -C linker=arm-linux-androideabi-gcc. Sorry for the false alarm. Now to figure out why Cargo is not passing this...

@lorcanmcdonald
Copy link

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"

@piegamesde
Copy link
Contributor

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)

@h0ru5
Copy link

h0ru5 commented Jul 5, 2020

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants