PC environment Ubuntu 14.04 64 bit
Set up the Cross tool chain 1. 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 execute the clone operation CD RPI
git clone git://github.com/raspberrypi/tools.git
CD ~/rpi/tools/arm-bcm2708/cloning can be done by pull update Tools CD ~/rpi/tools Git pull Origin
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-x643. Adding environmental environment variables
Add the GCC Cross tool chain catalog to the/.BASHRC file.
sudo gedit ~/.BASHRC "32-bit system" Export path= $PATH: $HOME/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/ Bin "64-bit system"
Export path= $PATH: $HOME/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian
-x64/bin
source. BASHRC
4. Simple test
In order to test whether the cross tool chain is installed successfully, you can enter
Arm-linux-gnueabihf-gcc-v not come out a lot of things, that's right. 2. A simple example file named HELLO-WORLD.C, which only tests the success of cross-compilation and simply tests the floating-point function.
- #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-LINUX-GNUEABIHF-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
cc=arm-linux-gnueabihf-gcc
hello-world:hello-world.o
Clean
RM-RF HELLO-WORLD.O Hello-world
At least two implied rules are used in the makefile file, and CC is the default toolchain; The *.O file is generated by the *.c file with the same name.
Then enter make in the console to generate the executable file.
Send me a compiled executable file for Raspberry Pi:
Scp-r ~/catkin_ws/src/beginner_tutorials/src/hello-world [Email Protected]:/home/ubuntu
"SSH login Execution" after landing into the directory where the executable file, modify the execution permissions of the file.
sudo chmod 755 hello-world./hello-world
Does it appear on the Raspberry Pi Terminal:
Hello World
6.28
That's OK.
The test is done. Delete: Rm-rf Hello-world (otherwise uncomfortable)
Raspberry Pi Learning notes-cross-compiling