Cross compile between ubuntu 16.04(x64) and raspberry pi(x64)

1. Machine’s setting up

  1. Ubuntu 16.04(x64) on the laptop
  2. Raspbian(x64) on the raspberry pi 3

2. Set up the developing environment

  1. Installing the general build tools:
    $ sudo apt-get install build-essential git

  2. installing the C and C++ compiler and build tools for the Pi’s ARM processor.
    $ sudo apt-get install g++-arm-linux-gnueabihf

  3. installs a version of the gdb debugging tool that works with target systems regardless of the processor architecture.
    $ sudo apt-get install gdb-multiarch

  4. Create a folder for install the cross_compile tools:
    $ cd pi
    $ git clone git://

  5. Edit the .bashrc file
    $ sudo vim ~/.bashrc

  6. add the fellowing line to the file (because the Raspbian is x64 system, use the x64 edition. The gcc-linaro-arm-linux-gnueabihf-raspbian is for x86 system):

    # added for the cross compile tools for raspberry pi
    export PATH=$PATH:$HOME/pi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin
  7. Reboot the system
    $ reboot

  8. Test the installation of cross_compile_tools
    $ arm-linux-gnueabihf-g++ -v

for updating the tools
cd ~/pi/tools
git pull origin

3. Example for cross_compile with 2 methods

  1. Creat the file with name: hellow-word.c
  2. Paste the fellowing lines to the file
    #include <stdio.h>
    int main(void)
        float pi = 3.14;    
        printf("Hello World\n");

1. Method 1: Cross compile with command

  1. Cross compile the file with command from terminal:
    $ arm-linux-gnueabihf-gcc hello-world.c -o hello-world

  2. Run the file:
    $ ./hello-word

2. Method 2: Cross compile with Makefile

  1. Create a file with name: Makefile
  2. Paste the line to the file:

    CC=arm-linux-gnueabihf-gcc //cross_compile with arm-linux-gnueabihf-gcc
    hello-world:hello-world.o // hello-word.o is created by the file hello-word.c
        rm -rf hello-world.o hello-world
  3. Create an executive file by make:
    $ make

  4. Run the file:
    $ ./hello-word

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.