Monday , August 8 2022
Home / Rust / Rust Cross Compilation between Computer to Raspberry Pi 4

Rust Cross Compilation between Computer to Raspberry Pi 4

Amora March 7, 2020 Rust Leave a comment 3,444 Views I have just set up the new Ubuntu Machine and have nothing in it.
Now, Let’s start our work, which is how to use the cross-compiling of Rust Lang in Ubuntu to Raspbian Buster. After updating the Linux Ubuntu, we have. Now, open the terminal and type this command on it.
sudo apt-get install curl

Click enter, and you can install the curl.

After that, you can write this command onto the terminal.
curl -sSf | sh

Hit the enter button and then press 1 to Proceed with installation (default)

After installation is finished, you see this message in which you set the environment variable.
source $HOME/.cargo/env

Now install the cargo by using this command.
sudo apt-get install cargo

Press Y and continue the setup.

After doing it. Now, lets come to the major portion of this Cross-Compilation. You need to install the C linker by using this command.
sudo apt install build-essential
Press Y and continue to install this.

After the installation, you see this screen in your machine.

Now, you have to install the global cross compiler of the cc linker.
sudo apt-get install -qq gcc-arm-linux-gnueabihf
Press enter to continue the send.

After completion of this, we have seen this window.

Now type this command onto the terminal.
mkdir -p ~/.cargo
Press hit the enter button.

Now, open the file in this directory.
sudo nano ~/.cargo/config
Place this content on it.
linker = "arm-linux-gnueabihf-gcc"

After putting the text on the nano. Now, press the Crt X, Y, and Press the Enter.

Add the rust target for the raspberry pi 3 and 4 series.
rustup target add armv7-unknown-linux-gnueabihf
Hit the enter.

After the installation, now you see this window.

Now, you need to install the rust in the raspberry pi as well.
so now, you just need to have the raspberry pi in an open network where you can access it from your local or public network.
curl -sSf | sh
Hit the enter button.

Press 1 and hit the enter button to continue this.

So, both the Machine and Raspberry Pi is set for the cross-compilation. Now, we only need to compile the project on a specific target.
Now, create the new Binary project of rust.
cargo new rust_cross –bin
then hit the enter button.

Then change the directory.
cd rust_cross
Further, you can add this line to compile on the specific target.
cargo build --target armv7-unknown-linux-gnueabihf

By doing this, you compile the project for Raspberry Pi.
scp ./target/armv7-unknown-linux-gnueabihf/debug/rust_cross
Type yes and then hit enter

Enter the password, and you have successfully sent the file into the Raspberry Pi.

Finally, you need to type this command into the Raspberry Pi into the ~ home directory.

Lastly, you have now successfully did the job.

About Faheem

An adaptable and responsible Software Engineer, who enjoys working with computers and the opportunity to learn new skills and work with new technologies is particularly attractive to me.

Check Also

Linux Installation on Computer in Hindi/Urdu

In this article, you can find the way you can install Linux on your own …

Leave a Reply

Your email address will not be published.