The concept of cross-compilation and the installation of cross-compilation tools

Table of contents

1. What is cross compilation

2. Why cross compile?

3. Installation of the cross-compilation chain

4. Related usage methods

Five. Soft connection


1. What is cross compilation

Cross-compilation refers to the compilation of programs written in one programming language into programs in another programming language, usually for use in different operating systems or hardware environments. This compilation process produces one or more binary files that can be run on another operating system or hardware environment. In short, it is to generate executable code for another platform on one platform.


2. Why cross compile?

1. Due to the lack of resources on the target platform, the compiler we need cannot be run

2. Does the Raspberry Pi not require cross-compilation?

wrong. Also, Raspberry Pi is sometimes because the target platform has not yet been established, and there is no operating system, so it is impossible to talk about running any compiler. The operating system is also code and must be compiled!

The platform needs at least two things: bootloader (boot code) and operating system core

Host (host): The platform for editing and compiling programs, generally an X86-based PC, also known as a host.

Target machine (target): The system developed by the user is usually a non-X86 platform. The executable code compiled by the host runs on the target.


3. Installation of the cross-compilation chain

1. Open the URL: https://github.com/raspberrypi/

2. Select tool

 3. Click to download

4. Create a new folder and copy it from the shared folder to the working directory

cp /mnt/hgfs/share/tools-master.zip .

Put the downloaded tools-master.zip into it and unzip it

unzip tools-master.zip

5. Go to the corresponding file 

cd tools-master
cd arm-bcm2708/
cd gcc-linaro-arm-linux-gnueabihf-raspbian-x64
cd /bin

6. Configure environment variables

echo $PATH shows environment variables

 Configure temporary environment variables

export PATH=/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/CLC/lessonPI/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin

Or you can also configure permanent and effective environment variables

Modify the .bashrc hidden file in the working directory

vi /home/liujiaxin/.bashrc 

Add in the last line of the file: 

export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/liujiaxin/lessonPi/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin

 Load the configuration file and the configuration will take effect immediately.


4. Related usage methods

1. How to use cross-compilation:

arm-linux-gnueabihf-gcc  xxx.c -o xxx

 2. Use the -v parameter to view the version information of the GCC compiler

 3. Upload the virtual machine code to the Raspberry Pi

scp clientInPi [email protected]:/home/

Command File Name Development Board Username@Development Board Address: Absolute path of the development board

4.file Executable file name: View file type


Five. Soft connection

Soft link concept: 1. Soft link files have shortcuts similar to Windows.

                     2. In a symbolic link, the file is actually a text file that contains information about the location of another file.

                     3. Generate a mirror image of the file on the location you choose, which will not take up disk space

How to generate:

ln -s libwiringPi.so.2.50 libwiringPi.so

Guess you like

Origin blog.csdn.net/aaaaaaaa123345/article/details/129005174