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

Can not cross compile for target aarch64-linux-gnu-gcc due to linking error "error adding symbols: file in wrong format" #43

Open
BoolPurist opened this issue Nov 25, 2022 · 6 comments

Comments

@BoolPurist
Copy link

BoolPurist commented Nov 25, 2022

What is the problem

I want to cross compile on fedora 37 amd 64 bit for a rasberry pi 4, arm 64 bit.
I can cross compile a hello world program for this target. However as soon as I use this crate in the project, the cross compiling fails with an linking error /aarch64-unknown-linux-gnu/debug/deps/librpi_led_matrix_sys-d20828d1ca08a5b2.rlib: error adding symbols: file in wrong format.

Rust set up

rustc version

rustc 1.65.0 (897e37553 2022-11-02)

rust toolchain

installed toolchains
--------------------

stable-x86_64-unknown-linux-gnu (default)
nightly-x86_64-unknown-linux-gnu

installed targets for active toolchain
--------------------------------------

aarch64-unknown-linux-gnu
armv7-unknown-linux-gnueabihf
x86_64-unknown-linux-gnu

active toolchain
----------------

stable-x86_64-unknown-linux-gnu (default)
rustc 1.65.0 (897e37553 2022-11-02)

How to reproduce it

I cross compile via this command

cargo build --target aarch64-unknown-linux-gnu

For this code

use rpi_led_matrix::{LedColor, LedMatrix};

fn main() {
    let matrix = LedMatrix::new(None, None).expect("Could not create led matrix from options");
    let mut canvas = matrix.offscreen_canvas();
    for red in 0..255 {
        for green in 0..255 {
            for blue in 0..255 {
                canvas.fill(&LedColor { red, green, blue });
                canvas = matrix.swap(canvas);
            }
        }
    }
}

Error output

   Compiling led_matrix v0.1.0 (/home/nicegraphi/Code/rust/LedMatrixInf)
error: linking with `aarch64-linux-gnu-gcc` failed: exit status: 1
  |
  = note: "aarch64-linux-gnu-gcc" "/tmp/rustcXPqgt8/symbols.o" "/home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps/led_matrix-c1e7d078d0007520.1826tw3csssunte5.rcgu.o" "/home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps/led_matrix-c1e7d078d0007520.2ff05qk8jmu9l08h.rcgu.o" "/home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps/led_matrix-c1e7d078d0007520.2u3fw9wgfj54e3eh.rcgu.o" "/home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps/led_matrix-c1e7d078d0007520.2u78656zh9kh0r5w.rcgu.o" "/home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps/led_matrix-c1e7d078d0007520.2vguhu8z0ndppkh7.rcgu.o" "/home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps/led_matrix-c1e7d078d0007520.341jrsfsc8rb8drs.rcgu.o" "/home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps/led_matrix-c1e7d078d0007520.3dl0odp5weyipdgc.rcgu.o" "/home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps/led_matrix-c1e7d078d0007520.3oo094vgey4n82jv.rcgu.o" "/home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps/led_matrix-c1e7d078d0007520.3za1b1ck4wef2062.rcgu.o" "/home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps/led_matrix-c1e7d078d0007520.4xmof5bev8sq57xl.rcgu.o" "/home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps/led_matrix-c1e7d078d0007520.99jk30mbiggor1t.rcgu.o" "/home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps/led_matrix-c1e7d078d0007520.gmm87eakcji2w4g.rcgu.o" "/home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps/led_matrix-c1e7d078d0007520.42tvuzb7j9lbf48y.rcgu.o" "-Wl,--as-needed" "-L" "/home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps" "-L" "/home/nicegraphi/Code/rust/LedMatrixInf/target/debug/deps" "-L" "/home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/build/rpi-led-matrix-sys-51f97f517a6f991b/out/cpp-library/lib" "-L" "/home/nicegraphi/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps/librpi_led_matrix-f41353ffb9e61f71.rlib" "/home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps/librpi_led_matrix_sys-d20828d1ca08a5b2.rlib" "/home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps/libembedded_graphics_core-0b75ae2412192dbc.rlib" "/home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps/libaz-ae2afb26aa1ca46a.rlib" "/home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps/liblibc-bcfccfaeff17cb80.rlib" "/home/nicegraphi/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib/libstd-ed4e5bf94d2d8a70.rlib" "/home/nicegraphi/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib/libpanic_unwind-bebdd5eea372668b.rlib" "/home/nicegraphi/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib/libobject-3355bc0b98aa4a8c.rlib" "/home/nicegraphi/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib/libmemchr-0b5aa3d64bc8a557.rlib" "/home/nicegraphi/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib/libaddr2line-f641304dbaaf4a6c.rlib" "/home/nicegraphi/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib/libgimli-93e9b8c66d37f69d.rlib" "/home/nicegraphi/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib/librustc_demangle-50982f8036d6f83d.rlib" "/home/nicegraphi/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib/libstd_detect-5eeb69397bccea91.rlib" "/home/nicegraphi/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib/libhashbrown-2b679d626836b073.rlib" "/home/nicegraphi/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib/libminiz_oxide-9a98cf221fb4b2c0.rlib" "/home/nicegraphi/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib/libadler-b5dca51dab735af9.rlib" "/home/nicegraphi/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-29342939a4c4f765.rlib" "/home/nicegraphi/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib/libunwind-d8b64b175ae3dad2.rlib" "/home/nicegraphi/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib/libcfg_if-1671a6ea0c5ac033.rlib" "/home/nicegraphi/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib/liblibc-e64d7cdeda4c1ec1.rlib" "/home/nicegraphi/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib/liballoc-def74c7c4b1b311e.rlib" "/home/nicegraphi/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib/librustc_std_workspace_core-18ea8bd63a028a62.rlib" "/home/nicegraphi/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib/libcore-d20cd64dc93f727e.rlib" "/home/nicegraphi/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib/libcompiler_builtins-b598f65ae2808d30.rlib" "-Wl,-Bdynamic" "-lstdc++" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/home/nicegraphi/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib" "-o" "/home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps/led_matrix-c1e7d078d0007520" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs"
  = note: /usr/lib/gcc/aarch64-linux-gnu/12/../../../../aarch64-linux-gnu/bin/ld: /home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps/librpi_led_matrix_sys-d20828d1ca08a5b2.rlib(led-matrix-c.o): Relocations in generic ELF (EM: 62)
          /usr/lib/gcc/aarch64-linux-gnu/12/../../../../aarch64-linux-gnu/bin/ld: /home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps/librpi_led_matrix_sys-d20828d1ca08a5b2.rlib(led-matrix-c.o): Relocations in generic ELF (EM: 62)
          /usr/lib/gcc/aarch64-linux-gnu/12/../../../../aarch64-linux-gnu/bin/ld: /home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps/librpi_led_matrix_sys-d20828d1ca08a5b2.rlib(led-matrix-c.o): Relocations in generic ELF (EM: 62)
          /usr/lib/gcc/aarch64-linux-gnu/12/../../../../aarch64-linux-gnu/bin/ld: /home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps/librpi_led_matrix_sys-d20828d1ca08a5b2.rlib(led-matrix-c.o): Relocations in generic ELF (EM: 62)
          /usr/lib/gcc/aarch64-linux-gnu/12/../../../../aarch64-linux-gnu/bin/ld: /home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps/librpi_led_matrix_sys-d20828d1ca08a5b2.rlib(led-matrix-c.o): Relocations in generic ELF (EM: 62)
          /usr/lib/gcc/aarch64-linux-gnu/12/../../../../aarch64-linux-gnu/bin/ld: /home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps/librpi_led_matrix_sys-d20828d1ca08a5b2.rlib: error adding symbols: file in wrong format
          collect2: error: ld returned 1 exit status
          

error: could not compile `led_matrix` due to previous error

Verbose output of compiling


       Fresh winapi-build v0.1.1
       Fresh winapi v0.2.8
       Fresh tinyvec_macros v0.1.0
       Fresh kernel32-sys v0.2.2
       Fresh tinyvec v1.6.0
       Fresh walkdir v0.1.8
       Fresh unicode-normalization v0.1.22
       Fresh copy_dir v0.1.2
       Fresh unicode-bidi v0.3.8
       Fresh percent-encoding v2.2.0
       Fresh form_urlencoded v1.1.0
       Fresh memchr v2.5.0
       Fresh idna v0.3.0
       Fresh libc v0.2.137
       Fresh az v1.2.1
       Fresh byteorder v1.4.3
       Fresh bytes v1.3.0
       Fresh embedded-graphics-core v0.3.3
       Fresh rpi-led-matrix-sys v0.2.1
       Fresh url v2.3.1
       Fresh combine v4.6.6
       Fresh ryu v1.0.11
       Fresh itoa v1.0.4
       Fresh sha1_smol v1.0.0
       Fresh redis v0.22.1
       Fresh rpi-led-matrix v0.4.0
   Compiling led_matrix v0.1.0 (/home/nicegraphi/Code/rust/LedMatrixInf)
     Running `rustc --crate-name led_matrix --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=967c1c49fdc89db5 -C extra-filename=-967c1c49fdc89db5 --out-dir /home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps --target aarch64-unknown-linux-gnu -C linker=aarch64-linux-gnu-gcc -C incremental=/home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/incremental -L dependency=/home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps -L dependency=/home/nicegraphi/Code/rust/LedMatrixInf/target/debug/deps --extern redis=/home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps/libredis-c9a0c1f937416ca7.rlib --extern rpi_led_matrix=/home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps/librpi_led_matrix-2975166824ff955d.rlib -L native=/home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/build/rpi-led-matrix-sys-950d1431edd7ee32/out/cpp-library/lib`

My cross compiling set up for the target aarch64-linux-gnu-gcc

I develop on fedora 37.

  • I tried to compile with copr provided cross compiler. Link.
  • I tried to compile with the rust tool "cross" Link.

Both approaches yield the same error.

@BoolPurist
Copy link
Author

BoolPurist commented Nov 25, 2022

Now I can cross compile.
Solution: I had to include the c-stub feature for this crate via this line in the Cargo.toml file.

rpi-led-matrix = { version="0.4.0", default-features=true, features=["c-stubs"] }

However this of course stops linking to c++ library.

@TDHolmes
Copy link

I also have not been able to cross compile before, thus the existence of the c-stubs for compilation in CI. I never dug in very much as to why to be honest.

I wonder if the library produced assumes 32 bit? I don't recall what rpi I used to use for this development.

Can you run file on librpi_led_matrix_sys-d20828d1ca08a5b2.rlib?

@TDHolmes
Copy link

Have you tried enabling the feature for statically linking to c++ std lib?

@BoolPurist
Copy link
Author

I also have not been able to cross compile before, thus the existence of the c-stubs for compilation in CI. I never dug in very much as to why to be honest.

I wonder if the library produced assumes 32 bit? I don't recall what rpi I used to use for this development.

Can you run file on librpi_led_matrix_sys-d20828d1ca08a5b2.rlib?

Jup can file this rlib file. Output of file command

file /home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps/librpi_led_matrix_sys-ca5e82262bd20cd5.rlib

is the following.

/home/nicegraphi/Code/rust/LedMatrixInf/target/aarch64-unknown-linux-gnu/debug/deps/librpi_led_matrix_sys-ca5e82262bd20cd5.rlib: current ar archive

@BoolPurist
Copy link
Author

Have you tried enabling the feature for statically linking to c++ std lib?

Yes, i did.

If I only use the feature with statically linking to c++ std lib.

rpi-led-matrix = { version="0.4.0", default-features=true, features = ["stdcpp-static-link"] }

Then I get the following error message:

rror: could not find native static library `stdc++`, perhaps an -L flag is missing?

error: could not compile `rpi-led-matrix-sys` due to previous error
warning: build failed, waiting for other jobs to finish... 

If I use both feature with c-stubs and linking to c++ library statically

rpi-led-matrix = { version="0.4.0", default-features=true, features = ["stdcpp-static-link", "c-stubs"] }

then it compiles. My question is here, does it still link to the stubs or then to c++ library instead ?

@TDHolmes
Copy link

It'll only link to the C stubs. The rpi library depends on the C++ standard library, C stubs does not

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

2 participants