Installation, compilation and operation of cross-compilation environment in Linux environment

Install a virtual machine on the Win11 host and run Ubuntu20.04 in the virtual machine. In order to develop test software and algorithms on the local computer (Win11), the compiled executable file is finally copied to the Linux board (linux system running on Rk3288) To run, a cross-compilation toolchain needs to be installed.

For example: gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf

1. Steps to install the cross-compilation toolchain

1) Copy the downloaded cross-compilation tool to the Ubuntu system of the virtual machine.

         Linaro Releases

2) Copy to the specified path

sudo mkdir /usr/local/arm
sudo cp gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf.tar.gz /usr/local/arm/ -f

3) Unzip the cross-compilation toolchain

sudo tar -vxf gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf.tar.gz

4) Modify environment variables

sudo vim /etc/profile

Inside that file add the following: 


export PATH=$PATH:/usr/local/arm/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin
Make the configuration take effect
source /etc/profile

5) The cross-compilation toolchain installation is successfully verified

arm-linux-gnueabihf-gcc -v

2. Use the cross-compilation tool chain to compile a simple helloworld program

 2.1Writing a program

touch hello.cpp
#include <stdio.h>
int main()
{
  printf("hello world!\n");
}

2.2 Compiler

arm-linux-gnueabihf-gcc  hello.cpp -o hello

compile program

Just copy it to the Linux board and run it (note that the cross-compiled executable file (arm) cannot run on a win11 computer).

Precautions:

1) Prompt error 1

 The reason is: the characters are in Chinese and the uppercase and lowercase characters are inconsistent. Just recheck the code and recompile.

Guess you like

Origin blog.csdn.net/heda3/article/details/132408916