Raspberry Pi Learning notes-cross-compiling

Source: Internet
Author: User

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.
    1. #include <stdio.h>
    2. int main (void)
    3. {
    4. float pi = 3.14;
    5. printf ("Hello world\n");
    6. printf ("%.2f\n", 2*PI);
    7. }
"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

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.