Some questions about cross-compiling

I have used Rust for a period, and I have basic knowledge about Rust, but I still don't have a no idea how to cross compile, I think cross-compile is not as easy as I thought.

Problem1: I usually worked on aarch64 linux, I have tried compile my code to x86_64-unknown-linux-musl by added its target by rustup and modified .cargo/config like follows, and everything goes well.

[target.x86_64-unknown-linux-musl]
linker="lld"

Then I tried compile to aarch64-unknown-linux-gnu which is my host but modified the config additionally like this:

[target.aarch64-unknown-linux-gnu]
linker="lld"

But it didn't worked as expectation this time.

...A dozen of command...
= note: lld: error: unable to find library -lgcc_s
          lld: error: unable to find library -lutil
          lld: error: unable to find library -lrt
          lld: error: unable to find library -lpthread
          lld: error: unable to find library -lm
          lld: error: unable to find library -ldl
          lld: error: unable to find library -lc


error: aborting due to previous error; 9 warnings emitted

error: could not compile `mcmu`

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

Then I tried to compile to x86_64-pc-windows-gnu as above did, but it also printed similar errors.
Why can I compile to x86 Linux but cannot compile to aarch64 Linux and windows even aarch64 Linux is my device's host? Am I have nothing to do except installing linkers for every platform?

Problem2:
If not, does it possible to install these missing library? How to do it? I have searched on the Internet for a long time but in vain.

Is there anybody can help me? Thanks!

I recommend you to use this https://github.com/rust-embedded/cross which will help you to handle the deps issues.

Through the dockerfile you could find some examples about how to install the missing library https://github.com/rust-embedded/cross/blob/master/docker/Dockerfile.aarch64-unknown-linux-gnu#L12-L14.

Thanks, but I have trouble installing Docker on my Android device temporarily, I starred the repository and would find a way to solve the problem later, thank you all the same.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.