Cross Compiler Setup

#1

Being rather new to RUST, I was attempting to cross compile but the binaries are for x86, while I need to have it be for an ARM 7 (i.mx6q).

Compiles via Cargo come up with this error.

$ cargo
/home/gfine/.rustup/toolchains/stable-armv7-unknown-linux-gnueabihf/bin/cargo: 1: /home/gfine/.rustup/toolchains/stable-armv7-unknown-linux-gnueabihf/bin/cargo: Syntax error: word unexpected (expecting “)”)

I tried uninstalling,
and then reinstalling the cross compiler via :

rustup install stable-armv7-unknown-linux-gnueabihf
info: syncing channel updates for ‘stable-armv7-unknown-linux-gnueabihf’
info: latest update on 2019-04-25, rust version 1.34.1 (fc50f328b 2019-04-24)
info: downloading component ‘rustc’
69.2 MiB / 69.2 MiB (100 %) 5.3 MiB/s ETA: 0 s
info: downloading component ‘rust-std’
52.2 MiB / 52.2 MiB (100 %) 5.2 MiB/s ETA: 0 s
info: downloading component ‘cargo’
info: installing component ‘rustc’
69.2 MiB / 69.2 MiB (100 %) 16.7 MiB/s ETA: 0 s
info: installing component ‘rust-std’
52.2 MiB / 52.2 MiB (100 %) 19.3 MiB/s ETA: 0 s
info: installing component ‘cargo’

stable-armv7-unknown-linux-gnueabihf installed - (error reading rustc version)

info: checking for self-updates
info: downloading self-update

$ rustup show
Default host: x86_64-unknown-linux-gnu

installed toolchains

stable-armv7-unknown-linux-gnueabihf (default)
stable-x86_64-unknown-linux-gnu

active toolchain

stable-armv7-unknown-linux-gnueabihf (default)
(error reading rustc version)

As I said, I am rather new to RUST and am at an impasse.

Known bug?? Is there a workaround?

Glen

#2

For cross compiling, you need to keep using stable-x86_64-unknown-linux-gnu matching your current host, but then rustup target add armv7-unknown-linux-gnueabihf to get rust-std for your target.

You will also need a cross-compile cc for linking – again built to run on your x86_64 host but with libraries for the target.

1 Like
#3

Follow the steps in rust-cross, to install the correct toolchain and in particular add

[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"

to you’re .cargo/config (more details). Then build with

cargo build --target=armv7-unknown-linux-gnueabihf
1 Like
#4

Thank you. ehsanmok

I inherited the code from another.

Still trying to make sense of some things. Was trying a build of the app on the target when I got the familiar ‘Exec format error’ telling me the binary was not for the target.

$ cat .cargo/config
[target.armv7-unknown-linux-gnueabihf]
ar = “arm-dey-linux-gnueabi-gcc-ar”
linker = “gcc-sysroot”

[build]
rustflags = ["-C", “prefer-dynamic”]

So this is what was there before, and I am not inclined to change it, but make it work.

Glen

#5

You are running the binary on your target machine not host, right?

#6

Yes, the binary is being executed on a target (arm based i.MX6Q) and not on the host.

#7

What I have found is the linker is specified as

linker = "gcc-sysroot’

in the config file. But how to tell rust to invoke gcc-sysroot is a mystery to me. That file is nowhere on my system. And yes, I understand this is usually a define like
SYSROOT=/home/user/sysroot where several toolchains can exist, and RUST will try to match to the proper gcc compiler that would fit the [target=arm7-unknown-linux-gnuabihf]
target.

G