(iii) Raspberry Pi cross-compilation environment configuration

Source: Internet
Author: User
Tags git clone
0. PrefaceWhy do you want to use cross-compilation for "1"
The speed at which the cross-compilation tool is developed faster. The Raspberry Pi has already installed the GCC toolchain, which can be compiled directly from the Raspberry Pi source code to generate the executable file. At the same time, the PC can also use the GCC toolchain to generate executable code, but unlike the GCC tools on the Raspberry Pi, the GCC tools on the PC generate Intel or AMD chip executable code, but the Raspberry Pi is the arm series of chips, obviously there is no small difference.     Then you can use the cross tool chain to develop a Raspberry Pi executable program on your PC. Although the frequency of the Raspberry Pi up to 700MHz is much higher than the general embedded system, but compared to the PC's performance is still worse, the use of cross-tool chain can save development time. When compiling code with the same size, the PC should take less time than the Raspberry Pi, and improve efficiency by cross-compiling.

"2" PC environment Ubuntu 14.04 AMD64 Please note that there are differences between 32-bit systems and 64-bit systems, please note the description of the relevant chapters in the blog post. The procedures in this document are tested in the Ubunut 14.04 AMD64 system, Lubuntu 14.04 i386 system (hard disk installation, non-virtual machine environment).
1. Set the Cross tool chain"1" Download the necessary software and tools sudo apt-get install build-essential git
"2" Clone crossover tool chain
Create a folder under the home path named RPI
mkdir RPI
Enter the directory and perform a clone operation (to correct an error)
CD RPI
git clone git://github.com/raspberrypi/tools.git
Please keep in mind that clone has a long time to wait patiently. After cloning is complete, you can go to the following directory to view the details of the toolchain.
CD ~/rpi/tools/arm-bcm2708/
"Special reminders" after cloning is complete, you can update the Tools CD ~/rpi/tools Git pull origin by pulling
There are 4 folders in this directory, this example uses Gcc-linaro-arm-linux-gnueabihf-raspbian or gcc-linaro-arm-linux-gnueabihf-raspbian-x64. The former corresponds to a 32-bit system which corresponds to a 64-bit system.
Arm-bcm2708hardfp-linux-gnueabi
Gcc-linaro-arm-linux-gnueabihf-raspbian Arm-bcm2708-linux-gnueabi
Gcc-linaro-arm-linux-gnueabihf-raspbian-x64
"3" Add environment environment variable
Add the GCC Cross tool chain catalog to the/.BASHRC file.
sudo gedit ~/.BASHRC
At the end of the file, add the directory where the cross tool chain resides. Note that the ~ symbol represents the home path,. BASHRC is a hidden file.
"32-bit system" Export path= $PATH: $HOME/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin (gcc problematic, unknown) exp ORT path= $PATH: $HOME/rpi/tools/arm-bcm2708-linux-gnueabi/bin (using gcc in this file)
"64-bit system"
Export path= $PATH: $HOME/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian -x64/bin export path= $PATH: $HOME/rpi/tools/arm-bcm2708-linux-gnueabi/bin
Note that path represents an environment variable: The colon represents the append. Save and exit the file, and then execute the following instruction to immediately update the environment variables that are contained in the current console.
source. BASHRC

"4" Simple test
In order to test whether the cross tool chain is installed successfully, you can enter the output in the ARM-BCM2708-LINUX-GNUEABI-GCC-V console in the console to verify that the cross-tool chain is installed and that the environment variable is set correctly.

Figure 1 ARM-LINUX-GNUEABIHF-GCC version information

2. A simple exampleWrite a test file, complete the compilation on the PC and upload it to the Raspberry Pi via FTP and execute it.
The "Test code" file is named HELLO-WORLD.C, which tests only cross-compilation success and simply tests the floating-point function.
[CPP]View plain copy #include <stdio.h> int main (void) {float pi = 3.14;       printf ("Hello world\n");   printf ("%.2f\n", 2*PI); }
"Cross-compiling-simple Instructions"
CD into the directory where the HELLO-WORLD.C is located, enter the following instructions to generate the executable file.     Note that the executable file cannot be run on a PC. ARM-BCM2708-LINUX-GNUEABI-GCC Hello-world.c-o Hello-world can eventually generate Hello-world executables in the same directory as HELLO-WORLD.C.
"Cross-compiling--makefile"
Of course, you can also create a makefile file under this directory, the simple makefile file is as follows
[Plain]View Plain Copy CC=ARM-LINUX-GNUEABIHF-GCC HELLO-WORLD:HELLO-WORLD.O

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.