[Solved] Cross compile to aarch64 from windows10

Greetings,

using rust for a while, and I just got myself some few orangepi devices lately..
I am trying to compile from windows10 machine(MINGW64_NT-10.0) a simple hello world and try to run it in a aarch64 system(and hopefully other devices too like omega 2+). it works obviously in cargo run but when I try cargo build --target aarch64-unknown-linux-gnu it doesn't work..

here is the complete the complete command and error.

$ cargo build --target aarch64-unknown-linux-gnu --release
   Compiling hello v0.1.0 (file:///D:/Developer/rust/hello)
error: linker `aarch64-buildroot-linux-gnu-gcc` not found
  |
  = note: The system cannot find the file specified. (os error 2)

error: aborting due to previous error

error: Could not compile `hello`.

To learn more, run the command again with --verbose.

I have looked other tutorials and steps, but can't get it correct. I will post some information on my system..

// toolchain list
$ rustup toolchain list
stable-aarch64-unknown-linux-gnu
stable-mipsel-unknown-linux-gnu
stable-x86_64-pc-windows-msvc
nightly-aarch64-unknown-linux-gnu
nightly-mipsel-unknown-linux-gnu
nightly-x86_64-pc-windows-msvc (default)
// rustup version
$ rustup --version
rustup 1.13.0 (ea9259c1b 2018-07-16)

// cargo version
$ cargo version
cargo 1.29.0-nightly (0ec7281b9 2018-08-20)

// .cargo/config
$ cat ~/.cargo/config
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-buildroot-linux-gnu-gcc"

Maybe this does help you

https://stackoverflow.com/questions/53496847/rust-compile-x86-library-on-x86-64-machine

thank you for the response.. but I don't think this will work, as it is the same steps that I am following, and the last part apt-get install will not work as I am using windows w/o subsystem..

Rust doesn't know how to make executables, and relies on the linker to do it for it. So you have to find and install a cross-linker and Linux system libraries yourself.

The linker path in ~/.cargo/config is not part of Rust. It has to point to actual name of the Linux-compatible linker you find and install on your machine.

Thank you for the response.. Do you have any examples or can you point me to somewhere as a start?

I will continue to try to work on this as I am eager running some server to aarch64.. Thanks..

Afaik lld, the linker from LLVM, is shipped with rust now, so you can use that to link it. I'm not quiet sure how to do it though. You may need to crawl through a few github posts or this reddit post.

If you had success, we would like to hear your story!

hey guys, I just gotten home and setting up another windows machine.. and I am following the above link. now the error has changed.

$ cargo build --target=aarch64-unknown-linux-gnu
   Compiling hello_arm v0.1.0 (D:\Developer\rust\hello_arm)
error: linker `lld` not found
  |
  = note: The system cannot find the file specified. (os error 2)

error: aborting due to previous error

error: Could not compile `hello_arm`.

To learn more, run the command again with --verbose.

I know I can finish this in linux/mac, as there are lots of tutorials. but I am windows now, with so much cores that made my switch..

will read more!

finally got this shit working..

so here are the steps cross compiling from windows10(MINGW64_NT-10.0) to aarch64

  1. download toolchain bins from here. I downloaded gcc-linaro-5.5.0-2017.10-i686-mingw32_aarch64-linux-gnu
  2. unpack it, and quickly put the bins in $ PATH=$PATH:/e/Downloads/gcc-linaro-5.5.0-2017.10-i686-mingw32_aarch64-linux-gnu/bin
  3. update .cargo/config
$ cat ~/.cargo/config
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
  1. finally build it
$ cargo build --target=aarch64-unknown-linux-gnu --verbose
   Compiling hello_arm v0.1.0 (D:\Developer\rust\hello_arm)
     Running `rustc --crate-name hello_arm 'src\main.rs' --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=657544e897501478 -C extra-filename=-657544e897501478 --out-dir 'D:\Developer\rust\hello_arm\target\aarch64-unknown-linux-gnu\debug\deps' --target aarch64-unknown-linux-gnu -C linker=aarch64-linux-gnu-gcc -C 'incremental=D:\Developer\rust\hello_arm\target\aarch64-unknown-linux-gnu\debug\incremental' -L 'dependency=D:\Developer\rust\hello_arm\target\aarch64-unknown-linux-gnu\debug\deps' -L 'dependency=D:\Developer\rust\hello_arm\target\debug\deps'`
    Finished dev [unoptimized + debuginfo] target(s) in 1.20s
  1. lastly, ship it to my orangepi
    scp -r target/aarch64-unknown-linux-gnu/debug/ jeanepaul@192.168.1.7:/home/jeanepaul/developer/rust/hello_arm

and that's it!

jeanepaul@orangepizeroplus:~/developer/rust/hello_arm/debug$ uname -a
Linux orangepizeroplus 4.14.70-sunxi64 #274 SMP Wed Sep 19 12:09:30 CEST 2018 aarch64 aarch64 aarch64 GNU/Linux
jeanepaul@orangepizeroplus:~/developer/rust/hello_arm/debug$ ./hello_arm
Hello, world! jeane

this work for the meantime, but I will look more on how to use the LLD and update this post.

hope this can give a hint to anyone who wants to cross compile to aarch6 or anything if lost..

4 Likes

also, got rocket running from orangepi

jeanepaul@orangepizeroplus:~/developer/rust/hello-rocket2/debug$ ROCKET_ADDRESS=0.0.0.0 ./hello-rocket2
� Configured for development.
    => address: 0.0.0.0
    => port: 8000
    => log: normal
    => workers: 8
    => secret key: generated
    => limits: forms = 32KiB
    => keep-alive: 5s
    => tls: disabled
�   Mounting /:
    => GET / (index)
� Rocket has launched from http://0.0.0.0:8000
GET /:
    => Matched: GET / (index)
    => Outcome: Success
    => Response succeeded.
GET / text/html:
    => Matched: GET / (index)
    => Outcome: Success
    => Response succeeded.
GET /favicon.ico image/webp:
    => Error: No matching routes for GET /favicon.ico image/webp.
    => Warning: Responding with 404 Not Found catcher.
    => Response succeeded.

if anyone tried this, there is a little failure when you build..

I solve it by

  1. setting TARGET_AR=aarch64-linux-gnu-ar..

so build it by TARGET_AR=aarch64-linux-gnu-ar cargo build --target=aarch64-unknown-linux-gnu --verbose and it'll be fine

now.. time to port some web api'`s to the greatest and famous rust-lang..

2 Likes