Development Environment for the Raspberry Pi using a Cross Compiling Toolchain and Eclipse

UPDATED July 15th 2013

In this blog entry the setup of  a cross-compiling development environment for the Raspberry Pi will be demonstrated. This will include the

We will finally write a simple Hello World program on our development PC, compile it using the cross compiler and then deploy it onto our Raspberry Pi board to run it.

I’m going to assume that you have already installed a Raspbian Wheezy image on your RPi board and that you have Linux installed on your desktop PC.  For this tutorial I am using the Crunchbang 11 Linux OS (64-bit) on my PC. The instructions provided should work on most Debian/Ubuntu based Linux distributions running directly on a PC or as a  a guest operating system via VMWare/ VirtualBox .

A remote debugging tutorial; which I consider to be the continuation of this tutorial, can be found here.

Finally, Derek Molloy has a great video tutorial on setting up a similar environment for the Beaglebone. Watching this video was incredibly informative and helped me set up this tutorial.

So what is a cross compiling toolchain and why use one ?

A native compiler such as the default gcc tool on the PC  is a compiler that runs on an Intel machine, as well as creates binaries intended to be run on an Intel machine. i.e it creates binaries for the same type of machine that it runs on. Similarly the GCC tool in the RPi’s Raspbian Linux OS is intended to run on an ARM machine as well as creates binaries for an ARM machine.

A cross compiler such as the “arm-linux-gnueabihf-gcc” that we will use, is able to run on an Intel machine but creates binaries for an ARM machine. In other words, it runs on one architecture and creates binaries for another. This allows us to develop and compile our programs/libraries on our Desktop PC, but when it comes to deploying the binaries/libraries we deploy them and run them on the Raspberry Pi.

So why use a cross-compiler instead of  developing our code and compiling it natively on the Raspberry Pi itself? After all, the Raspberry Pi has a native GCC compiler. We can also use code editors such as nano or vi from the command line (remotely over SSH) or GUI programs such as Geany (remotely over VNC).

The main case for cross-compilation over native compilation (develop and compile on the RPi itself) is that it tends to be faster. Remember the RPi board may be fast compared to a microcontroller…but its still has limited RAM resources and is pretty slow compared to an average desktop computer….

Also you have a myriad of development tools that you can use on your desktop PC that you simply can’t use on the Raspberry Pi; such as the Eclipse IDE.

Cross compilation of simple applications that only require the use of the standard C/C++ libraries included with the cross compiling toolchain is relatively straightforward. Cross compilation of more complicated applications that require external libraries however (such as libjpeg, GTK+, Qt4/5 e.t.c),  is typically more complicated to setup  and is  out of the scope of this tutorial.

Cross compiling applications requiring external libraries, requires that all necessary libraries be cross-compiled from source as well and included in the build process. Furthermore some libraries such as GTK+ depend on multiple other libraries that must also be cross compiled and included in the build process. In this case it may be more convenient (if slower) to build these projects natively on the RPi, because the RPi is capable of retrieving these libraries using the apt-get package manager (if they are not already included in the root file-system) without having to cross compile every single required library and all if its dependencies manually.

Tools that ease the process of cross compiling large projects with multiple external libraries include Scratchbox and Buildroot. Again these tools are out of the scope of this tutorial but I do encourage those interested in cross-compiling applications requiring multiple dependencies to take a look at them.  Finally, if you specifically want to cross compile:

  • GTK+ applications for the Raspberry Pi, take a look at this blog entry.
  • QT4 applications for the Raspberry Pi, take a look at this blog entry.

Now that I’ve briefly explained the pros & cons of cross compilation…let’s get started!


Downloading and Setting Up the Cross Compiling Toolchain

  • Open a terminal window on your desktop Linux OS and type the following command:
sudo apt-get install build-essential git

This will install the native build tools on your PC along with the GIT tool which  will be used to download / clone the cross compiling toolchain from GitHub.com.

  • If you’re running a 64-bit Ubuntu/Kubuntu Linux OS 12.04 you will also want to install the 32-bit library/header files. Since the cross compiler will need them to properly run. You can do this by typing:
sudo apt-get install ia32-libs
sudo apt-get install libc6:i386 libgcc1:i386 gcc-4.6-base:i386 libstdc++5:i386 libstdc++6:i386 lib32z1 lib32ncurses5 lib32bz2-1.0 lib32asound2
  • If you are running Debian Wheezy or Crunchbang Linux, you will first have to enable the 32-bit package repos:
dpkg --add-architecture i386

and then update:

 apt-get update

Both commands must be run as root. Feel free to use “sudo” if you have it already installed on your machine. Once the 32-bit repos are added run as root:

apt-get install ia32-libs

If that doesn’t work, then runas root:

apt-get install libc6:i386 libgcc1:i386 gcc-4.6-base:i386 libstdc++5:i386 libstdc++6:i386 lib32z1 lib32ncurses5 lib32bz2-1.0 lib32asound2

If you’re not sure whether you’re running a 64-bit or 32-bit Linux OS, open a terminal window and type” uname -a“. If  the output of that command contains “i686″ or “i386″, you’re running a 32-bit Linux OS. If in the output you see “amd64″ then you’re running a 64-bit Linux OS.

  •  Create a “rpi” directory in your home directory by typing “
mkdir rpi

while in your home directory.

  • Go to the rpi directory with:
cd rpi
  • and then type:
git clone git://github.com/raspberrypi/tools.git
  • This command will download (clone) Raspbian’s official cross compiling toolchain from Github. The command will take a few minutes to complete its task.
  • UPDATE: Please ignore this has now been fixed As of February 2014, the github repo above contains a more recent version of the cross-compiler that is unfortunately not functional. I’m hoping that this is fixed soon. As a quick fix you can revert to the older functional version of the toolchain.  After the “sudo git clone…” command do the following; “cd tools” followed by “sudo git checkout HEAD~1″.
  • When the previous command completes, navigate to “/home/halherta/rpi/tools/arm-bcm2708″:
cd ~/rpi/tools/arm-bcm2708

on your deskop Linux OS. Note that My username is “halherta” and therefore my home folder is “/home/halherta”. Please substitute your username with mine where necessary.

  • In the arm-bcm2708 folder you’ll see three other folders each containing a separate toolchain:
  1.  arm-bcm2708-linux-gnueabi
  2.  arm-bcm2708hardfp-linux-gnueabi
  3.  gcc-linaro-arm-linux-gnueabihf-raspbian

Of those three we will use the third one.  The next step is to add the directory containing the binary files of the third toolchain “gcc-linaro-arm-linux-gnueabihf-raspbian” to the PATH environment variable in linux. This way we can access the toolchain’s binary files/tools from the command line.  This step is not necessary if you want to using the toolchain strictly from Eclipse. I still do highly recommend that you do it, in case you decide to compile/debug  arm applications directly from the command line later on. We will do this by adding an “export PATH”  command to the bottom of the .bashrc  files in the home directory.

  • In a terminal window (on your Desktop Linux OS) type:
cd ~/

to point to the home directory, then type:

nano .bashrc

This will open the .bashrc file in a command line based editor called nano. Go to the bottom of the .bashrc file using the down arrow key. Then type the following command:

export PATH=$PATH:$HOME/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin
  • Then hit Ctrl+x to exit. You will be prompted to save changes. Say yes and hit “Enter”.
  • Then type:
source .bashrc

This allows the current open terminal to see the updated PATH variable. Alternatively one can  close the terminal and open a new one.

  • To test if you can access the cross compiling toolchain from the command line type:
 arm-linux-gnueabihf-gcc -v

If you were successful, you should see output similar to that in Figure 1. Congratulations! you just installed Raspbian’s official cross compiling toolchain on your Desktop PC / Virtual machine!

Figure 1. Cross Compiling Toolchain successfully installed and accessible from anywhere within your Desktop side Linux OS!!!

Figure 1. Cross Compiling Toolchain successfully installed and accessible from anywhere within your Desktop side Linux OS!!!

Downloading and Setting Up Eclipse

The Next step is to download and install Eclipse. Unfortunately as of this writing the apt-get repositories rarely contain the latest Eclipse build.. So we will not be using the apt-get package manager. Instead we will download the latest Eclipse IDE from the web using a web browser.

  • Before we can run Eclipse, we need to ensure that we have a Java runtime environment installed; since Eclipse relies heavily on Java. We can do this with the following command:
sudo apt-get install openjdk-7-jre
  • Go to the link provided below and download the latest linux version of the Eclipse IDE  for C/C++. Download the 32-bit version of the IDE if you’re running a 32-bit Linux OS or download the 64-bit version of the IDE if you’re running a 64-bit Linux OS.

Link: http://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers/keplerr

  • The next step is to extract the “eclipse” folder into our home directory from the eclipse-cpp-kepler-R-linux-gtk-x86_64.tar.gz compressed file. This can be easily done using  File Manager and Archive Manager.  Alternatively to perform the extraction from the command line, open a new console and navigate to the directory containing the .gz file (typically “~/Downloads/”)then type:
tar -xvzf eclipse-cpp-kepler-R-linux-gtk-x86_64.tar.gz -C ~/

Either way you will end up having  the eclipse directory created in your home directory.

  • To start eclipse, go to the home directory:
cd ~/

then ‘cd’ your way into the eclipse folder

cd eclipse

then type.

./eclipse &

Alternatively you could simply type in the terminal:

~/eclipse/eclipse &

Creating a New Project in Eclipse

When Eclipse runs, it will first launch the workspace launcher. You will be prompted to choose a workspace directory. Accept the default (/home/halherta/workspace). Feel free to check the “Use this as the default and do not ask again” option if you feel inclined to do so. (You can always switch/change the workspace directory by going to “File->Switch Workspace” ).

  • If you see a  Welcome tab, click on the ‘x’ on the Welcome tab to close it.

There is a known bug in Eclipse whereby the application closes down and reports a GTK Error. If this happens to you, you will need to modify a .gtkrc configuration file in your home directory. Under Crunchbang Linux the exact name of that configuration file was “.gtkrc-2.0″. Open it in nano or any other editor of your choice and modify the “gtk-toolbar-icon-size” variable from “gtk-toolbar-icon-size=GTK_ICON_SIZE_SMALL_TOOLBAR” to “gtk-toolbar-icon-size=GTK_ICON_SIZE_LARGE_TOOLBAR”.

  • Now go to File->New->C++ Project. This will open the “C++ Project” window shown in Figure 2.
Figure 3. C++ Project Window

Figure 2. C++ Project Window

  • Type “HelloRpiWorld” in the “Project Name” field. Under Project type select “Executable->Empty Project” Under “Toolchains” select “Cross GCC”. Then click on “Next” This should take you to the “Select Configurations” Window. Accept the defaults and click “Next”.
  • This should then take you to the “Cross GCC command” Window (Figure 3).
    • In the “Cross compiler prefix” field type: “arm-linux-gnueabihf-”.
    • In the “Cross compiler path” field type the full path to the toolchain: “/home/halherta/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/”
    • Click Finish. This step informs Eclipse of the location of the cross compiling toolchain and its standard C/C++ libraries and headers.
Figure 4 Configure the Cross GCC path and prefix

Figure 3. Configure the Cross GCC path and prefix

    This should be the end of the basic project configuration. Your Eclipse environment should look as shown in Figure 4.
Figure 5. New Hello World Project initial setup

Figure 4. New Hello World Project initial setup

  • Notice how this project does not have any source files. So lets add one. Click on “File->New Source File”. This should open the “New Source File” window.
  • The “Source folder”  field should already have the project name “HelloRPiWorld” displayed in it. In the “Source file” field type “HelloRPiWorld.cpp” and click Finish. This will add a HelloRPiWorld.cpp source file to our project. In the source file copy the following C++ code:
/*
 * HelloRPiWorld.cpp
 */

#include <iostream>

using namespace std;

int main (void)
{
	cout << "Hello RPi Development World !"<< endl;
	return 0;
}
  • Save your project by clicking on “File->Save”.

To build the project click on “Project->Build Project”. To clean the project click on “Project->Clean”. Take note of the various options under the “Clean dialog box”  that enable multiple projects to be clean at once as well as automatic rebuild.  The output of the compilation/build process should be available for viewing in the “console” tab. Figure 5 shows the Eclipse workspace with the HelloWorld program successfully cross compiled for the Raspberry Pi!!!

Figure 6. HelloWorld program successfully compiled for Raspberry Pi.!!!

Figure 5. HelloWorld program successfully compiled for Raspberry Pi.!!!

The binary file for our HelloWorld application resides in  the “~/workspace/HelloRPiWorld/Debug”. Lets go there via a console window with cd:

cd ~/workspace/HelloRPiWorld/Debug/

Type

ls -al

The “HelloRPiWorld” Binary file is highlighted in green. The binary can be executed as follows

./HelloRPiWorld

but should output the followingerror message “cannot execute binary file“. Now type:

file HelloRPiWorld

You should get the following output:

HelloRPiWorld: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.26, BuildID[sha1]=0xb37e6eaa466429d015cc334d55f5d46c97c9fc6c, not stripped"

This indicates that the HelloRPiWorld Binary File was compiled for a 32-bit ARM machine and cannot run on an Intel Machine.

Deploying the Binary file onto the Raspberry Pi

To deploy the binary on the Raspberry Pi, make sure that the RPi board is powered and connected to your network. The next step is click on “Window->Show View->Other”. This will open a show view window. In this window select the “Remote Systems” folder and then select “Remote Systems Details” and press OK (Figure 6).

Figure 7. Remote system view

Figure 6. Remote system view

  • If the “Remote Systems Details” shows up in the bottom of the workspace, drag it such that its tab shares  the same region as the project explorer tab as shown in Figure 7.
Figure 8. Creating a New Connection

Figure 7. Creating a New Connection

  • Now right click in the “Remote Systems Detail” area and click on “New Connection”. In the “Select Remote System Type” window (Figure 8), select “SSH only” then click “Next”
Figure 9. Select remote system type

Figure 8. Select remote system type

    In the “Remote SSH Only System Connection” (Figure 9) type in the IP address of the RPi in the “Host name” field and give the connection a valid name in the “Connection name” field. I typed “Raspberry Pi”.  Then click “Finish”.
Figure 10. Remote SSH only system connection

Figure 9. Remote SSH only system connection

  • At this point a second device (Raspberry Pi) shows up in the “Remote Systems Detail” tab (Figure 10). Right click on the Raspberry Pi resource and click connect. You will be prompted to enter the username and password. Make sure that you utilize “username:pi” and “password:raspberry” (if you haven’t changed the default password). You may get a warning windows asking you if you are sure that you want to accept this connection. Affirm that you want to proceed with the connection. At this point you should be connected to your RPi from Eclipse.
Figure 11. Starting an SSH terminal in Eclipse

Figure 1o. Starting an SSH terminal in Eclipse

  • Right click on the Raspberry Pi resource again  in the “Remote Systems Detail” tab and click on the “Show in Remote Systems View”. This will open a “Remote Systems” tab in the same region of the workspace. In this tab, one can navigate the root file systems of both the Local Linux OS and that of the Raspbian/Raspberry Pi.
  • Locate the HelloWorld Binary file on our local desktop PC and drag it to the home directory on the Raspberry Pi (You could also right click on the binary and click on “Copy” and then right click on the home folder in the Raspberry Pi and click “Paste”. This effectively copies the binary file to the home directory of the Raspberry Pi.
Figure 12. Launch Terminal

Figure 11. Launch Terminal

  • Now right click on the SSH terminal icon under the Raspberry Pi icon (Figure 11) in the  “Remote Systems” and select “Launch Terminal” . This should launch a terminal window in the bottom of the Eclipse workspace (Figure 12). This is basically a console / terminal window connected to the Raspberry Pi via SSH.
Figure 13. Running the HelloRPiWorld binary on the Raspberry Pi via an eclipse's SSH terminal

Figure 12. Running the HelloRPiWorld binary on the Raspberry Pi via an eclipse’s SSH terminal

  • In the terminal window type
ls -al

to confirm that the “HelloWorld” binary indeed got copied into the home directory of the Raspberry Pi’s root file system. Then change the “HelloWorld” binary’s permission to make it executable:

chmod +x HelloWorld
  • Finally type
./HelloWorld

You should see the output shown in Figure 12 :“Hello RPi Development World !”

  • Congratulations!!! You just developed and ran your first cross compiled application for the Raspberry Pi.!!!!
  • To remotely debug your applications on the Raspberry Pi from Eclipse, check out this blog entry!


This entry was posted in Raspberry Pi, Raspberry Pi Cross Development. Bookmark the permalink.

198 Responses to Development Environment for the Raspberry Pi using a Cross Compiling Toolchain and Eclipse

  1. Kieron Quin says:

    This looks a really good simple guide, thinks for this.
    I guess this process should also work using the mac version of Eclipse too, albeit with some differences.
    Anyway, I’m going to give it a go and see what happens. What could possibly go wrong ;)

    Thanks again.

    Kieron

  2. Timon says:

    Perfect work!!!

    Thank you! :-)

  3. Nolan says:

    You, my friend, are a life saver! This saved me a ton of time. I don’t know how this tutorial was not the number 1 result on google for “raspberry pi cross compile”, but it should be.

    Cheers!

  4. mapi says:

    Simply great!
    Thanks!

  5. Steve Hobley says:

    Hi, I followed your directions with Kubuntu in a VM image. I can build the example application correctly but Eclipse is giving me a few errors regarding the code. It’s failing to recognise the include and use of ‘cout’ – and yet the compilation itself is fine. I posted images here : http://www.flickr.com/photos/stevehobley/8124559636/in/photostream
    http://www.flickr.com/photos/stevehobley/8124559612/in/photostream
    It looks like it is still using standard g++ environment for highlighting ‘bugs’, but the correct compilation environment when building the code. Is this something I can configure somewhere?

    • halherta says:

      Steve,
      you can disable the Eclipse errors by going to Window/Preferences – C/C++ / Code Analysis and disable “Syntax and Semantic Errors”.

      You shouldn’t have to do this however. Are you sure that you’ve included all the necessary library and include paths as per figures 10 and 11 ?

      UPDATE: Yes you need to install build-essentials if you haven’t already. I mentioned this in the “Setting up a Kubuntu virtual machine using VMware Player” article

      I will add this info to the blog entry thank you for the feedback and I’m glad that its working for you!

      • Steve Hobley says:

        Thanks – yes that was it.

      • Anders says:

        I had the exact same problem, but installing build-essential was not enough.
        I also had to add the following to Paths and Symbols (adjust base path to you RPi directory)

        /home/ubuntu/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/arm-linux-gnueabihf/include/c++/4.7.2
        /home/ubuntu/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/arm-linux-gnueabihf/include/c++/4.7.2/arm-linux-gnueabihf
        /home/ubuntu/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/arm-linux-gnueabihf/libc/usr/include/arm-linux-gnueabihf

        Cheers

        • Robin Breslin says:

          Where did you set these – in the include paths for Eclipse? or in unix files system links (ln) or in environment variables ($PATH)

          • halherta says:

            Robin, Anders comment refers to slightly outdated set of instructions that I changed in July 2013. Please let me know in what section of this tutorial are you having trouble and I’ll do what I can to help.

        • Mat says:

          Thanks for that tutorial and thanks for that comment Andres. I had to include this Paths and Symbols as well otherwise the cpp code in the next Tutorial (Remote- Debugging) don’t works. Means Eclipse couldn’t resolve the usleep function in the Header.

  6. Miki says:

    Slightly off-topic. Can you please tell me why are there different toolchains around? Most distros have an ARM targeted gcc and binutils. I use Arch and there is arm-elf-gcc-base. Why go through the trouble of getting other custom gcc’s?

    • halherta says:

      Miki you raise a great question. Theoretically any arm based toolchain could be used to compile code for the raspberry pi ..an ARM Machine. If the Kernel is compiled using the “hard float” option however, one should use a “hard float” (hf) compiler to get optimized binaries. Last time I checked the GIT repo for the Raspberry Pi tools there were three toolchains. The arm-bcm2708hardfp-linux-gnueabi & the gcc-linaro-arm-linux-gnueabihf-raspbian are both “hard float” and should both work on Raspbian which is itself (the Raspbian’s Linux Kernel) compiled with “hard float”. The other toolchain arm-bcm2708-linux-gnueabi is not “hf” and may or may not work well with Raspbian. Even if it does compile… it will not create lean fast optimized code…especially if one is doing a lot of numerical computing.

      I noticed that Ubuntu has recently added an armhf (with hard float) compiler to its repository which might very well compile code for the raspberry pi but I didn’t test it yet. Installing it is a simple matter of typing something like “sudo apt-get install gcc-arm-linux-gnueabihf” in your Kubuntu/Ubuntu Box.

      You can also create your own custom toolchain using the crosstool ng scripts. The process is simple and documented on many other blogs such as this. Make sure you select hardfp instead of softfp however in the menuconfig….

  7. Alco says:

    HI, I followed yor instructions, but…. now i’m stuck. I added the includes and the library paths and checked the command fields in the C/C++ Build -> Settings. The command fields seemed to still have the default commands. I entered the commands they should have, with no result. Now, when I try to build, the console tells me there is nothing to build. Can you give me a hint where i went wrong?

    • halherta says:

      Alco, You can try cleaning the project and then rebuilding. If you’ve already built the project and try to rebuild it again, it will say that there is nothing to rebuild.

  8. Daniel says:

    Hi! Excellent post!
    Can you tell me which tool chain you recommend when the OS in Raspberry PI is Arch Linux?
    I need to use another one or the one you choose on this post also fine?

    • halherta says:

      Daniel,
      I believe the toolchain that I’m using for this tutorial will be fine…..But I haven’t checked it myself. You can always try to create your own custom toolchain using the crosstools-ng scripts

    • Nate says:

      I just did this tutorial using Arch Linux and it worked just fine :)

  9. Martijn says:

    Hi, Thanks for the detailed instructions.
    The only problem I had was the missing of the make file. The cause of this problem is, I didn’t follow your insturctions about installing a virtual machine, while I already had installed Kubuntu in a virtualbox.
    In my virtualbox the build time is 8s.629 while on your system it take only 667ms. So I will follow your insturctions also to setup a virtualbox to see if it will compile much faster.

    • halherta says:

      Martijin,
      You do not need to use makefiles at all. Eclipse takes care of the entire build process for you. The build time will also depend on your machine. I’m using an Intel-I7 Core with 8GB of RAM. A slower machine might exhibit slower build speeds. Though if it takes you more than 8 seconds to build such a simple program, you maybe better off using the Raspberry Pi’s (Raspbian’s) native compiler and do all of your development on the Raspberry Pi itself.

      • Martijn says:

        Hi, thanks for the reply. While I used the virtualbox virtualmachine, in Eclipe C/C++ build Tool Chain Eiditor, the Current builder was set to Gnu Make Builder. If you change this to CDT Internal Builder than it is working, otherwise you have to install make.

        I installed a second virtual machine in VMPlayer according to your instructions. After this the build time is reduced to 2.22 sec. I’m using an Intel Core 2 Duo @ 2.2 GHz with 8GB of RAM. In the VMPlayer I select the option to use 2 cores.

  10. Alco says:

    A little late, but still, Thanks for your reply! I have struggled a lot, and failed to get it working on 64-bit ubuntu. Therefor I tried it on a Kubuntu VM last evening, and I finally got it working! Only now my Pi seems to have died, yet another challenge.

  11. Shiju P K says:

    Hi, I followed all the steps, But when I built the code i am getting following error

    **** Build of configuration Debug for project HelloRPi ****

    make all
    Building file: ../HelloRPi.cpp
    Invoking: GCC C++ Compiler
    arm-linux-gnueabihf-g++ -I/home/shiju/rasberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/arm-linux-gnueabihf/include -I/home/shiju/rasberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/arm-linux-gnueabihf/libc/usr/include -I/home/shiju/rasberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/lib/gcc/arm-linux-gnueabihf/4.7.2/include-fixed -I/home/shiju/rasberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/lib/gcc/arm-linux-gnueabihf/4.7.2/include -I/home/shiju/rasberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/lib/gcc/arm-linux-gnueabihf/4.7.2/finclude -O0 -g -Wall -c -fmessage-length=0 -MMD -MP -MF”HelloRPi.d” -MT”HelloRPi.d” -o “HelloRPi.o” “../HelloRPi.cpp”
    /bin/sh: 1: arm-linux-gnueabihf-g++: not found
    make: *** [HelloRPi.o] Error 127

    **** Build Finished ****

    any help??
    PS: I can run arm-linux-gnueabihf-g++ from terminal (i added bin to PATH)
    Thanks,
    -Shiju

    • halherta says:

      Shiju, If you are using Ubuntu / Kubuntu, you must add the toolchain binary directory to the PATH variable in both .bashrc and the .profile files in order to enable eclipse to see the toolchain binaries. This might be implemented differently in other distros….

      • Ranjan Batra says:

        Hi,

        I ensured that the export thing is all set and confirmed it by typing it in the terminal as explained. I am still getting the same error.

        Please help!

        Regards,
        Ranjan

        **** Build of configuration Debug for project Hello2 ****

        make all
        Building file: ../src/Hello.cpp
        /bin/sh: 1: arm-linux-gnueabihf-g++: not found
        Invoking: GCC C++ Compiler
        make: *** [src/Hello.o] Error 127
        arm-linux-gnueabihf-g++ -I/home/ranjan/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/arm-linux-gnueabihf/include -I/home/ranjan/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/arm-linux-gnueabihf/libc/usr/include -I/home/ranjan/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/lib/gcc/arm-linux-gnueabihf/4.7.2/include-fixed -I/home/ranjan/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/lib/gcc/arm-linux-gnueabihf/4.7.2/include -I/home/ranjan/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/lib/gcc/arm-linux-gnueabihf/4.7.2/finclude -I/home/ranjan/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian -O0 -g3 -Wall -c -fmessage-length=0 -v -MMD -MP -MF”src/Hello.d” -MT”src/Hello.d” -o “src/Hello.o” “../src/Hello.cpp”

        **** Build Finished ****

        • Ranjan Batra says:

          Hi,
          I could finally get it running! I used the Ubuntu 12 32 bit and eclipse for C/C++ Indigo. Things just worked smoothly.
          However, when I tried doing the same on the 64 bit Ubuntu, even after installing the lib32 files I was not able to compile the code. I got different errors on Juno and Indigo!
          I think 32 bit version is a safe bet!

          Cheers!

          Ranjan

  12. Andrea says:

    Hello, do you know how you can create a GUI application for raspberry using eclipse?

    • halherta says:

      Andrea,
      You will have to use an additional set of GUI Libraries such as QT and/or GTK.

      You would also have to cross compile these libraries first (using the cross compiler) before you can use them.

      If you want to use QT, checkout QTCreator its a great IDE that makes QT development easy.

      If you’re not concerned about speed, try developing QT applications natively on the Pi. just install QTCreator + QT Library on the Raspbian ..something like “sudo apt-get install qt-sdk”. This should work ok, especially if you have the 512MB Pi.

      Another way to achieve “cross compilation” (sort of) without a cross compiler is to simulate a Raspberry Pi environment using QEMU and then “chroot” into it. Check out the link below. You will still need to set the X-server to display GUI from the chrooted environment.

      http://superpiadventures.wordpress.com/

      By simulating Raspbian (ARM Linux) on your PC you will have little need to cross compile since you can compile using the native ARM GCC compiler in the simulated chrooted environment.

      I had some success with the chrooted setup but I found compilation to be relatively slow

      Also google QT5 for Raspberry Pi there’s lots of information on that on the web

  13. Mark Roberts says:

    I’m sure I’ve missed something… I’m stuck at building the HelloWorld project with an error “make:***[HelloWorld.o] Error 127″

    When I went back to default settings for the compilers, etc. it built o.k.

    • Mark Roberts says:

      Installing from scratch again cleared up my problem…
      -mark.

      • halherta says:

        Mark,
        Glad you were able to get it going! Were you able to figure out what was missing the first time round?

        • Paul Gullett says:

          I saw this when setting up on 64 bit Fedora 18. It was related to a missing 32 bit version of the zlib library. This was flagged in the log file for the compilation, found under the C/C++ Build section.

          As an aside the following are the required packages on 64 bit Fedora 18 to make this work.

          glibc.i686
          libstdc++-4.7.2-8.fc18.i686
          zlib-1.2.7-9.fc18.i686

  14. Garry Smith. says:

    Thanks for your tutorial.
    Unfortunately the compiled binary, when run on the Pi, creates a segmentation fault. I’m new to these gnu tools and I’m not sure where to start looking for the cause of this problem. Could you give me a starting point to find the cause.
    Thanks in advance, Garry

    • halherta says:

      You got a segmentation fault for a simple hello world program? That is very weird indeed. I will look at the procedure again and report back if I find something.

      In the mean time if you could try repeating the tutorial to see if you can fix this (preferably in a new virtual machine). One thing that I didn’t mention in this tutorial (I’m assuming you already have it) is that you may need to install the build-essentials package on your linux PC/VM (“sudo apt-get install build-essentials” in debian/ubuntu based distros). This package has primarily the native intel toolchain for the PC but it seems that eclipse requires some parts of it….(I doubt that was the problem but you can try it anyways if you haven’t already)

      • Garry Smith. says:

        Thanks for having a look at this and I’ll make sure that I install the build-essentials as you mention.
        Taking my lack of inexperience with GCC tools into account, is it likely that the libraries on the RPi are different to the ones that I built the binary on, would that be a problem. I did go back an start a new VM and followed the tutorial again with the same result. I did try a different tutorial as well (before I found yours’) and it produced the same result. I’m sure that there is something minor I’ve missed that is causing the problem. I’m setting up a Qemu Raspberry Pi emulator to see if the binary will run on that. In a divide and conquer manner. I could also sent you the binary to try on your RPi. This technique should tell us if it is the compiler setup or my RPi, or you could send me your Hello World binary to try on mine.
        (BTW I noticed that I had to tick the “Use Project Build options” (or similar) before the build would work.)
        Thanks again,
        Garry.

        • Garry Smith. says:

          I tried the HelloWorld binary in the Qemu RPi emulator and it ran as expected.
          The “file” information does say that it is using dynamically linked libraries. So I’ll try to work out which ones (somehow) and make sure that Qemu and RPi libraries match ( I recall that I had some problems apt-get library something or other while installing something on my pi. I could also burn a clean image on my RPi and try that.
          Thanks again.
          Garry.

          • Garry Smith. says:

            mmmm. Found the problem. and you probably not going to guess where.
            VM Debian Filezilla file upload. The file is 62,958 on the PC and is 63,023 on RPi. If I use Filezilla in windows the file is the same size and runs correctly. Noticed that ldd had an error of Non-executable binary(or similar) and no listing of used libraries.mmmm.
            Anyway problem found and a work around exists(be it painful to samba onto PC/c:/temp. WinFilezilla to RPi chmod ./HelloWorld). Hope this helps some one. Continuing on with your excellent Tutorial.
            Best regard,
            Garry.

        • halherta says:

          Garry, To build a simple program as HelloWorld, the libraries that you need are the stanard C/C++ libraries. These libraries must be compiled for ARM as well. Luckily these libraries are already compiled for arm and included in the toolchain so this should not be a problem. If however you decide at somepoint to cross compile code that uses other libraries, such as QT, GTK+, Libusb e.t.c then yes you would have to either compile these libraries from source for arm (using the arm cross-compiler) or find pre-built packages built for arm (with an toolchain that creates arm binaries)

  15. Garry Smith. says:

    or I could have just continued with your tut to realize I was dill. now removing egg from face. The rest of the tut works like a dream. Thanks – Garry.

  16. Maria says:

    Hi,
    Thanks for an easy-to-follow tutorial! it helps me a lot :)
    But now I need to cross compiling OpenNI to my Raspbian n don’t know where to start. Can I just add its library n headers from eclipse? or maybe build a correct toolchain?

    Thanks in advance,
    Maria

    • halherta says:

      Maria,
      Since you already have a cross-compiler for ARM (Raspberry Pi) installed on your PC, you should theoretically be able to compile the OpenNI library from source on your linux PC using the RPi (ARM) cross compiler. This will create the necessary library binaries (for ARM) which you can then link into your applications that will also be compiled by the cross compiler. If you have access to the source code for the openNI libraries this (theoretically) should not be a problem.

  17. luan says:

    I am having the same probrem that Garry Smith sad above. When I run on the Pi creates a segmentation fault. I didn’t understand how he solved this problem, could you help me?

    • halherta says:

      luan, are you building the helloworld program in eclipse ? Did you follow all of the instructions? I highly recommend that you use the RSE plugin (eclipse built-in SSH) to transfer the binary from your linux PC/VM to the Raspberry Pi before running the program.

    • Garry Smith. says:

      Hi Luan,
      The problem that I had was that I didn’t read the remainder of the Tut, which demonstrates how to use eclipse to download the binary exe file to the RPi. and boldly went ahead to use filezilla on my Debian Virtual Machine on a winXP pc. Filezilla changed the binary somehow (probably used text mode coping ) while downloading to the RPi to a point that the file would not run (segment fault). When I followed the remaining section of the Tutorial it was all good.
      What I found, apart from the file download prob, was the command line library usage information utility “lld” (lowercase LLD) and “file” these give you information about the libraries used and the the type of binary executable. ( Google them until you find an explanation that make sense to you.
      Let us know what you find. and if you need more help. ( I’m learning linux as I go).
      Garry.

      • luan says:

        Sorry for the late reply, I was traveling. Thank you for your replies.
        So, I follow all steps of this tutorial. I am using Eclipse Juno Service Release 1 and Ubuntu 12.10 in a host PC. The code compile and the binary is created very well. I use the RSE to transfer the binary for RPI. But, when I execute the program on RPI, the segmantation fault is created.
        I am new on linux. I will install other linux distro on my PC and try again. If I solve the problem I tell you here.
        Thanks.
        Luan

        • Josh says:

          I was wondering if this issue was ever resolved? I am running Ubuntu 12.04 LTS (64 bit) with Eclipse Juno Service Release 1 inside VMware Workstation 9. I followed all steps in the tutorial, but get a Segmentation Fault when I execute on the RPI.

          I’m also learning linux as I go, so any help would be greatly appreciated. My next step is to play with the Qemu emulator like Gary Smith suggested above. If that doesn’t work I could try another linux distro, but it seems I’m probably just missing something that someone with more experience could point out.

          This is a wonderful tutorial! I’m looking forward to starting my first RPI project, so getting a debugging environment setup would be a good first step.

          • halherta says:

            Josh, Did you transfer the binary over to the RPi using the RSE plugin ? Can you please provide me with the output of the following command: “file HelloWorld” (or “file [name of binary]“) when executed on ubuntu (in the directory in which the binary exists…..

          • Josh says:

            I did transfer the binary over to the RPi using the RSE plugin. The result of “file HelloWorld is below”.

            pi@raspberrypi ~ $ file HelloWorld
            HelloWorld: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.31, BuildID[sha1]=0x208ca613cce3f01ecb00705b772022e000ceb830, not stri
            pped

            I am curious if there is anything else that needs to be done since I am running a 64 bit host OS? I did install the iar32-libs as you mentioned above. I’m running Raspbian Wheezy on the RPi:
            http://downloads.raspberrypi.org/images/raspbian/2012-12-16-wheezy-raspbian/

            Thank you for your quick response. I appreciate the help!

          • Josh says:

            I created a new VM with Ubuntu 12.10 (32 bit) and everything worked beautifully after following Anders recommendation for the additional Paths and Symbols.

            I did notice that the file size is smaller on this build than Ubuntu 12.04 LTS (64 bit). The “file HelloWorld” command now returns:

            pi@ubuntu:~/workspace/HelloWorld/Debug$ file HelloWorld
            HelloWorld: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.26, BuildID[sha1]=0x3ad90103daea30331ca7d5dadf5f275b7a877a32, not stripped

            It looks like the GNU/Linux version is different (2.6.26 vs. 2.6.31). Being new to the tool chain, I would like to understand the difference between these and why it resulted in a Segmentation Fault when running on the RPi. However, I am happy that I have a working environment.

            Thanks again for this great tutorial!

  18. Francesco says:

    Thank you very much for the guide. I installed eclipse and toolchain on Ubuntu 10.10 in a VM. I followed your guide, built the example HelloWorld. Works fine, now beginning to fun

  19. Wael.Ch says:

    Thanks very very mush for the tutorial..
    I used to do all the instructions and every things goes right.
    BUT, in the end when i put “./firsttest” (firsttest is the name of my application), I got:

    “-bash: ./firsttest: No such file or directory”

    Please i need your help as soon as possible!!
    thank you so mush.

    • halherta says:

      Make sure that you’ve successfully transfered the file to the correct directory by running an “ls” command on the RPI via the SSH session. When transfering the file use the RSE plugin by dragging it from the Linux PC to the RPi home directory, sometimes the file is transfered to another folder within the home directory, Also make sure that you make the file executable with the chmod command. If the programs attempts to access certain resources such as GPIO then you will need to run it as root

  20. neil says:

    I found this a very usefull tutorial and hello world worked for me.
    However not being very familiar with the IDE I was wondering if there is an easy way to setup the project settings without having to carefully re-type the paths and compiler tool names. ie is there way of having a “template” of just these that can be imported or something like that. I did a google on adding new toolchains but this started to look very involved.

    • halherta says:

      neil,
      There most likely is a better way of setting up all of the paths but I’m not aware of it. If you this better way, I’d appreciate it if you could let me know.

  21. Steve says:

    Amazing tutorial worked great for Hello World App. I am working on a socket based app (in C) and Eclipse cannot seem to find defines such as AF_INET, SOCK_STREAM. I am having the same issue with the signal.h file as well. Are there other include paths needed? Sorry I am a complete noob to Linux programming.

  22. Steve says:

    Figured it out! Needed to add the following include path to the build

    /home/steve/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/arm-linux-gnueabihf/libc/usr/include/arm-linux-gnueabihf

  23. John says:

    Thanks for the tutorial, I found this extremely useful. I just wanted to know how one would link commonly used libraries. For instance, I want to use the pthread library – would it be correct to link by augmenting the compile commands by -lpthread (would this automatically use the pthread library in gcc-linaro-arm-linux-gnueabihf-raspbian directory?). Thanks

    • halherta says:

      John I haven’t used Eclipse in a while now, but you would need to specify the directory containing the libraries in the window in figure 10. You then have to specify the library name in the same window in figure 10 but under the “libraries” tab. From the command line you need to use the “-L” parameter to specify library directories and “-l” parameter to specify the library file in those directories to be linked to the project.

  24. Neil says:

    In addition to the above I have also found I needed to add two extra paths for c++ to get around eclipse bugging me with “unresolved inclusion” on #include

    My full list of include paths now looks like this :

    ${HOME}/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/arm-linux-gnueabihf/include

    ${HOME}/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/arm-linux-gnueabihf/libc/usr/include

    ${HOME}/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/arm-linux-gnueabihf/libc/usr/include/arm-linux-gnueabihf

    ${HOME}/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/lib/gcc/arm-linux-gnueabihf/4.7.2/include-fixed

    ${HOME}/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/lib/gcc/arm-linux-gnueabihf/4.7.2/include

    ${HOME}/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/lib/gcc/arm-linux-gnueabihf/4.7.2/finclude

    ${HOME}/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/arm-linux-gnueabihf/include/c++/4.7.2

    ${HOME}/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/arm-linux-gnueabihf/include/c++/4.7.2/arm-linux-gnueabihf

    • Charlie says:

      I too find that I had to include “/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/arm-linux-gnueabihf/libc/usr/include/arm-linux-gnueabihf” among the paths.

      The very important “sys” and “bits” directors are in there. Almost any real project is going to need these. Took me forever to figure this out too.

      I feel he really should at least add this to the tutorial.

  25. Neil says:

    What would be the correct approach to installing packages/librarys for use by the cross compiler on the host so they don’t get mixed up with the regular librarys.
    For example I added the jpeg library on the RPi using :

    sudo apt-get install libjpeg8-dev

    Now my Ubuntu host m/c already has this installed, well the i386 one atleast. So how does one install the armhf version without blowing holes in the existing installation ?

    • halherta says:

      Neil You would have to build the libjpeg8 binaries/library from source using the arm-linux-gnueabihf-gcc cross compiler on the Linux PC/VM. Then save it in its separate folder structure on the Linux PC/VM. Then reference the location of the library/include files in eclipse as you did with standard libraries/headers in figure 9 & 10. You will also need to specify the specific library to be linked under the “library” tab in properties window (see figure 9). This is how I think one would do it..at least theoretically. The problem with this approach is that you will also have to build any other dependencies that the libjpeg8 library might have in the same way.

      • Neil says:

        I did in the end sucessfully transfer the OpenGL ES2.0 library installed on the RPi to my KubuntuVM host by simply copying /opt/vc/* from one m/c to the other. I did have some problems with the compiler options before I could get something to compile and run. See http://www.raspberrypi.org/phpBB3/viewtopic.php?f=67&t=14863&sid=a4349da8a84b7f69138792145a388f63&p=259128#p259128

        However I felt my approch to this was something of “hack” rather than the proper way to do it, hence my question. However I do have an OpenVG example compiling on the host under the Eclipse IDE. I am about to have a go at you gdbserver tutorial as well.

        After a bit of google research I discovered that it might be possible to use a command such as “sudo apt-get install libjpeg8-dev:armhf” which I thought might install an already cross-compiled version of the library to my Kubuntu. I thought better of trying it for fear it would just just overlay on top of my i386 version of the same library.

        To re-build cross compiled librarys such as “libjpeg8-dev” how would I get the source installed on my Kubuntu ready for a “make” ?

        • halherta says:

          Neil, You should be able to download the libjpeg library from here . and installation instructions are here . Once you get the code, untar it and in its main directory type something like ” CC=arm-linux-gnueabihf-gcc ./configure –host=arm-linux –prefix=/opt/libjpeg” where the prefix determines where to place the compiled library files and –host determines which system will we be compiling for….I’m not sure for host if we need to specify “arm-linux” exactly but it ought to be something similar. Then “make” and “make install”.

          I cannot confirm that what’s above will work but hopefully it will give you a good start.

  26. Neil says:

    I have been able to make the libjpeg8 !
    Thanks for your guidance.

    I did it this way :
    a) Download source (I found that lastest source to be libjpeg-8d rather than the 6d you found) …
    wget http://ftp.de.debian.org/debian/pool/main/libj/libjpeg8/libjpeg8_8d.orig.tar.gz
    b) Unpack …
    tar -xvf libjpeg8_8d.orig.tar.gz
    c) Configure …
    cd jpeg-8d
    ./configure CC=arm-linux-gnueabihf-gcc –host=arm-linux –prefix=/opt/arm-linux-gnueabihf/libjpeg
    d) Build …
    make
    make install

    Lets see if I can build and run a test prog using the lib !

  27. Neil says:

    One curious thing I have noticed. The library I have built on the Kubuntu host is vastly larger than the same version of the library install on the RPi. Is there something seriously wrong, should I have added some kind of optimisation switch to the configure command ?

    On the RPi:
    pi@raspberrypi ~ $ ls -l /usr/lib/arm-linux-gnueabihf/libjpeg*
    -rw-r–r– 1 root root 267046 Apr 23 2012 /usr/lib/arm-linux-gnueabihf/libjpeg.a
    lrwxrwxrwx 1 root root 16 Apr 23 2012 /usr/lib/arm-linux-gnueabihf/libjpeg.so -> libjpeg.so.8.4.0
    lrwxrwxrwx 1 root root 16 Apr 23 2012 /usr/lib/arm-linux-gnueabihf/libjpeg.so.8 -> libjpeg.so.8.4.0
    -rw-r–r– 1 root root 209436 Apr 23 2012 /usr/lib/arm-linux-gnueabihf/libjpeg.so.8.4.0
    pi@raspberrypi ~ $

    On Kubuntu :
    nurquhar@KubuntuVM:/opt/arm-linux-gnueabihf/libjpeg$ ls -l lib
    total 2552
    -rw-r–r– 1 nurquhar nurquhar 1567384 Jan 15 11:13 libjpeg.a
    -rwxr-xr-x 1 nurquhar nurquhar 940 Jan 15 11:13 libjpeg.la
    lrwxrwxrwx 1 nurquhar nurquhar 16 Jan 15 11:13 libjpeg.so -> libjpeg.so.8.4.0
    lrwxrwxrwx 1 nurquhar nurquhar 16 Jan 15 11:13 libjpeg.so.8 -> libjpeg.so.8.4.0
    -rwxr-xr-x 1 nurquhar nurquhar 1037464 Jan 15 11:13 libjpeg.so.8.4.0
    nurquhar@KubuntuVM:/opt/arm-linux-gnueabihf/libjpeg$

    • halherta says:

      Neil, I’m not really sure why that would be the case. Optimization might be the culprit. Basically to optimize for size you need to use the -Os flag with the arm-linux-gnueabihf-gcc….But I’m not sure exactly how I would do that from the configure file…there’s probably a way

  28. Neil says:

    Using the -Os flag makes a significant differance. Roughly 1/4 the size !
    nurquhar@KubuntuVM:/opt/arm-linux-gnueabihf/libjpeg.small/lib$ ls -l
    total 440
    -rw-r–r– 1 root root 240516 Jan 18 16:24 libjpeg.a
    -rwxr-xr-x 1 root root 946 Jan 18 16:24 libjpeg.la
    lrwxrwxrwx 1 root root 16 Jan 18 16:24 libjpeg.so -> libjpeg.so.8.4.0
    lrwxrwxrwx 1 root root 16 Jan 18 16:24 libjpeg.so.8 -> libjpeg.so.8.4.0
    -rwxr-xr-x 1 root root 201505 Jan 18 16:24 libjpeg.so.8.4.0
    nurquhar@KubuntuVM:/opt/arm-linux-gnueabihf/libjpeg.small/lib$

    I added the -Os flag like this :
    ./configure CC=arm-linux-gnueabihf-gcc CFLAGS=-Os –host=arm-linux –prefix=/opt/arm-linux-gnueabihf/libjpeg.small

    I did try building the lib on the RPi as well but the size was much the same as on the Kubuntu (without the -Os flag).

    • halherta says:

      Neil, good to hear that cross compiling with the -Os flag made such a difference on libjpeg8. Not sure why this wasn’t the case on the RPi (native compilation) though

  29. anon says:

    You do not need to sudo freaking everything. Especially editing files in your home directory. That is a bad habit to encourage.

    You also do not need to restart to make .profile changes take effect. Just type . ~/.profile

    You also do not need to put it in both files. It tends to vary by distro. It’s .profile on Ubuntu and .bashrc on Centos.

    • halherta says:

      Anon,
      you are correct. There are a few places where i used sudo when i didn’t need to. I’ve edited this.

      When I tried adding the toolchains directory to the PATH in either the .bashrc or .profile file, Eclipse was unable to to detect the toolchain. When modifying the PATH variable in both files however it worked….still trying to understand why.

      I will try the . ~/.profile command for reloading the .profile settings and then make an edit. Thanks.

  30. Sravan says:

    Hi thanks a lot !!! but when i run the same code i came up with these 2 errors as i am new to raspberry pi can you suggest me which are the things to be corrected for my code to run on raspberry
    http://www.flickr.com/photos/92715793@N05/8430587634/in/photostream

    • halherta says:

      Sravan,
      Are you sure that you set up the “GCC C++ linker” (Figure 11) properly ? The reason I’m asking this is that the error message seems to imply that there is a problem with the linking.

  31. chgian says:

    Excellent tutorial. Some problem that arose, were because of my mistakes. You cannot
    imagine how much did you help me. Thanks a lot

  32. Ryler says:

    Thanks a lot! It worked like a charm!
    I will post a link to your tutorial in my blog!

  33. darkladen says:

    I’m very very glad with you “Good TUTORIAL”. Is the best that I found for the web. Now I need to use qt5 and WebKit and make a little program, this prog have to show a web browser and a navbar.

    Well, Thanks a lot !!!!

    • halherta says:

      darkladen glad to you found this valuable. For QT5 one would need to compile the QT5 source code using the croos compiler. I’ve been trying to do this for sometime but with no avail. If you are successful, I’d appreciate it if you can refer me to the instructions that you followed! thanks

      • darkladen says:

        halherta, my news is I’ve been trying but always fail in this task (sorry for my english). The only one way that I found to install qt5 on pi, is by way of this repo (http://twolife.be/raspbian/). Here you found packages of qt5.

        I have tried with a lot of guides in internet, but nothing worked. I hope find some guide soon and make cross-compile can work 100% in raspbian.

        Greeting.

  34. Arne says:

    after connecting to the pi I can expand the ‘Sftp Files’ folder, but trying to expand ‘My Home’ or ‘Root’, it just displays ‘pending..’ and a window pops up asking for a password. After giving it the raspberry password the popup closes, only to open again after a couple of seconds. Nothing else happens, can’t get past this..

    • halherta says:

      Arne, is the RSE Plugin SSH setup configured correctly ? I’d say that is the culprit..Sometimes the IP address of the RPI will change if its on a DHCP enabled home network (all Home networks ought to be DHCP enabled).

  35. Stephan says:

    Hi,
    Thank you very much for the tutorial. I have the same problem than Wael.Ch.

    I make sure the file is executable (chmod +x) and I get the error “-bash: ./HelloCross: No such file or directory”

    When I recompile the code directly on the Raspi, it execute correctly. It looks like the binary is not in a good format. I load the soft float wheezy on the Raspi. Would Would it work the same on the SF and HF?

    Thanks

    • Stephan says:

      Ok, I found the solution myself. My Wheezy image was soft-float. I changed the config of the build with the appropriate tools and it worked fine now.

      • halherta says:

        Stephan sorry for the delay in replying. The toolchain being used in this tutorial is “hf” based and so you would need to have an “hf” based OS for it to work. Raspbian OS Wheezy or Arch Linux should be OK

  36. Stephan says:

    I don’t know if you can help, it is probably a newby question. I was able to cross compile the Hello World project, but I am stuck with the cross compilation of the wiringPi library from Gordon. I would like to remote debug on the Rasberry Pi and use wiringPi and i2c-dev library. When I try to compile, I am missing references. I create a new C library project and add all the source and header files of the wiringPi library. I am getting the following errors when I build the library:

    gnueabi/sysroot/usr/lib/crt1.o: In function `_start’:
    init.c:(.text+0×34): undefined reference to `main’
    wiringPiI2C.o: In function `wiringPiI2CRead’:
    /home/stephan/workspace/wiringPi/Debug/../wiringPiI2C.c:43: undefined reference to `i2c_smbus_read_byte’
    wiringPiI2C.o: In function `wiringPiI2CReadReg8′:
    /home/stephan/workspace/wiringPi/Debug/../wiringPiI2C.c:55: undefined reference to `i2c_smbus_read_byte_data’
    wiringPiI2C.o: In function `wiringPiI2CReadReg16′:
    /home/stephan/workspace/wiringPi/Debug/../wiringPiI2C.c:60: undefined reference to `i2c_smbus_read_word_data’
    wiringPiI2C.o: In function `wiringPiI2CWrite’:
    /home/stephan/workspace/wiringPi/Debug/../wiringPiI2C.c:72: undefined reference to `i2c_smbus_write_byte’
    wiringPiI2C.o: In function `wiringPiI2CWriteReg8′:
    /home/stephan/workspace/wiringPi/Debug/../wiringPiI2C.c:84: undefined reference to `i2c_smbus_write_byte_data’
    wiringPiI2C.o: In function `wiringPiI2CWriteReg16′:
    /home/stephan/workspace/wiringPi/Debug/../wiringPiI2C.c:89: undefined reference to `i2c_smbus_write_word_data’
    wiringPi.o: In function `wiringPiISR’:
    /home/stephan/workspace/wiringPi/Debug/../wiringPi.c:1144: undefined reference to `pthread_create’
    softTone.o: In function `softToneCreate’:
    /home/stephan/workspace/wiringPi/Debug/../softTone.c:115: undefined reference to `piThreadCreate’
    softServo.o: In function `softServoSetup’:
    /home/stephan/workspace/wiringPi/Debug/../softServo.c:210: undefined reference to `piThreadCreate’
    softPwm.o: In function `softPwmCreate’:
    /home/stephan/workspace/wiringPi/Debug/../softPwm.c:124: undefined reference to `piThreadCreate’

    Thanks for any help

    • halherta says:

      looks like eclipse is unable to find the pthreads library (used by the PiThreadCreate function) in the toolchain nor is it able to find the i2c-dev header required for the i2c calls.

      If you look under the …/tools / arm-bcm2708 / gcc-linaro-arm-linux-gnueabihf-raspbian / arm-linux-gnueabihf / libc / lib / arm-linux-gnueabihf/ and …/tools / arm-bcm2708 / gcc-linaro-arm-linux-gnueabihf-raspbian / arm-linux-gnueabihf / libc / usr / lib / arm-linux-gnueabihf /, you’ll find the pthreads library there. You need to include these direcctories (specifically the second one) in your library paths (fig10). In the same window in fig10 but under the “libraries: tab make sure to add “pthread”……to include this library (pthread) in the build.

      also include the following in ‘includes’ (fig 9) ../https://github.com/raspberrypi/tools/tree/master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/arm-linux-gnueabihf/libc/usr/include this has the pthreads.h include file

      for i2c-dev.h add the following directory to your include paths (fig 9)
      …../tools / arm-bcm2708 / gcc-linaro-arm-linux-gnueabihf-raspbian / arm-linux-gnueabihf / libc / usr / include / linux

      I think this should cover it. Try it and let me know.

  37. Stephan says:

    I am getting the following errors, pretty sure it is about the I2C-DEV.

    gnueabi/sysroot/usr/lib/crt1.o: In function `_start’:
    init.c:(.text+0×34): undefined reference to `main’
    wiringPiI2C.o: In function `wiringPiI2CRead’:
    /home/stephan/workspace/wiringPi/Debug/../wiringPiI2C.c:43: undefined reference to `i2c_smbus_read_byte’
    wiringPiI2C.o: In function `wiringPiI2CReadReg8′:
    /home/stephan/workspace/wiringPi/Debug/../wiringPiI2C.c:55: undefined reference to `i2c_smbus_read_byte_data’
    wiringPiI2C.o: In function `wiringPiI2CReadReg16′:
    /home/stephan/workspace/wiringPi/Debug/../wiringPiI2C.c:60: undefined reference to `i2c_smbus_read_word_data’
    wiringPiI2C.o: In function `wiringPiI2CWrite’:
    /home/stephan/workspace/wiringPi/Debug/../wiringPiI2C.c:72: undefined reference to `i2c_smbus_write_byte’
    wiringPiI2C.o: In function `wiringPiI2CWriteReg8′:
    /home/stephan/workspace/wiringPi/Debug/../wiringPiI2C.c:84: undefined reference to `i2c_smbus_write_byte_data’
    wiringPiI2C.o: In function `wiringPiI2CWriteReg16′:
    /home/stephan/workspace/wiringPi/Debug/../wiringPiI2C.c:89: undefined reference to `i2c_smbus_write_word_data’
    softTone.o: In function `softToneCreate’:
    /home/stephan/workspace/wiringPi/Debug/../softTone.c:115: undefined reference to `piThreadCreate’
    softServo.o: In function `softServoSetup’:
    /home/stephan/workspace/wiringPi/Debug/../softServo.c:210: undefined reference to `piThreadCreate’
    softPwm.o: In function `softPwmCreate’:
    /home/stephan/workspace/wiringPi/Debug/../softPwm.c:124: undefined reference to `piThreadCreate’
    collect2: error: ld returned 1 exit status
    Build error occurred, build is stopped
    Time consumed: 19005 ms.

    The goal of cross recompiling the wiringPi library is to be able to use it in another project. The wiringPi library is compiled and installed on the Rasberry Pi. I mount a DFS folder to the wirinPi source and library and add the path to Eclipse. I copied both files libwiringPi.so.1 and libwiringPi.so.1.0 to the dfs folder.

    When I build, I am getting the following error:

    /home/stephan/raspberrypi/tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/bin/../lib/gcc/arm-bcm2708-linux-gnueabi/4.7.1/../../../../arm-bcm2708-linux-gnueabi/bin/ld: cannot find -lwiringPi

    I am using teh soft-float wheezy image, thats why I use arm-bcm2708-linux-gnueabi tools.

    Thanks for your help.

    • halherta says:

      When creating a new project use the “CROSS GCC” option instead of the “LINUX GCC” option. This will then take you to a window where you get to specify the toolchain directory. By doing this, Eclipse will automatically know the paths of all the libraries that are available with the toolchain ( primarily libc)…(I will be modifying the instructions in the tutorial to reflect this soon). At this point under project properties you just need to specify pthread to explicitly ask the gcc to build the pthread library along with your project. Ofcourse make sure that you include all WiringPi headers/source files in the project (if you choose to organize the library in separate directories i.e. put the headers in an “include” directory, You will need to specifically let eclipse know about the path for that include directory as well.

      I was able to build an application with WiringPi (from source with no I2C stuff) using this technique (used the “hf” toolchain since I’m running the “hf” toolchain).

      For the I2C, if you basically want to use the core sysfs i2c driver as shown here, I think you (I haven’t actually tried this however) only need to include the i2c headers (#include linux/i2c.h & linux/i2c-dev.h ) into your code.

      Also check this link.

      If however you want to use the i2c_smbus_writeXX functions for doing I2C you will need to cross compile the “libi2c-dev” library and include it in your library path…I do not think that this is included with the toolchain.

    • Stephan says:

      Today, I success to include the wiringPi shared library into my cross compilie project. I just create a symbolic link called libwiringPi.so pointing to libwiringPi.so.1.

      • Valdir says:

        How I can do this? I have the same error messages.

        Thanks

        • Stephan says:

          First, I export the /Home/pi folder on the Raspberry and I mount the folder to my Kubuntu /home/stephan/pi. That way, I have access to the raspi folders directly from Kubuntu and I can refer to those folder in Eclipse.

          If you are talking about wiringPi, you need to install the library on the raspi following the instructions from Gordon’s web site. The installation of the wiringPi lib copy 2 files under /usr/local/lib, libwiringPi.so.1 and libwiringPi.so.1.0. I copied those 2 files under /home/pi/wiringPi folder. In that same folder, I created a symbolic link libwiringPi.so pointing to the file /home/pi/wiringPi/libwiringPi.so.1.

          In your project settings GCC C++ Compiler->Inculdes, I added the path /home/stephan/pi/wiringPi/wiringPi/wiringPi (NFS mounted folder from teh raspi)
          In your project settings GCC C++ Linker->Libraries I add the path /home/stephan/pi/wiringPi, (NFS mounted folder from the raspi)
          Also specified a -l wiringPi

          Not sure if it is necessary, but I also add the library path in the Eclipse settings C/C++ General ->Paths and Symbols->Library Paths the path where I created the symbolic link “/home/stephan/pi/wiringPi”

          Any time you want to use a library that is not supported by the toolchain, you need to compile it first on the Raspberry and make the files available to your Eclipse environnement. I where able to make de SQLITE3 worked the same way.

          Hope this will help.

  38. altella says:

    Thank you for the detailed tutorial, after following it step by step, I obtain the following error:
    make:***[HelloRaspberryPi.o] Error 127

    I do not have a clue of it, I have followed all the steps until figure 11.. I am very interested in being able to compile things in Eclipse, but with this error I am lost… any help?

    Thank you very much !!

    • halherta says:

      It could very well be that Eclipse is unable to find the cross compiler. You maybe also missing a few packages. Which Linux Distro are you using ? are you using 32-bit or 64-bit version?

      • altella says:

        I am using Xubuntu 12.04 64 bit version. My eclipse is 64 bit either. I have followed everything and I have obtained good results until trying to compile. In Xubuntu there is not a .profile, so the path has only been redefined in .bashrc…

        • halherta says:

          When creating a new project use the “CROSS GCC” option instead of the “LINUX GCC” option. This will then take you to a window where you get to specify the toolchain directory. By doing this, Eclipse will automatically know the paths of all the libraries that are available with the toolchain ( primarily libc)…(I will be modifying the instructions in the tutorial to reflect this soon). You will not need to do the steps shown in Fig 9 & Fig 10 since all of this stuff will be taken care of by Eclipse automatically. You also should not have any problems with eclipse recognizing your toolchain with this setup.

  39. Pingback: Problems cross compiling with Kubuntu & eclipse & gcc for the Raspberry Pi.

  40. Pingback: Cross-compiling & debugging for RaspberryPi using CMake and gdbserver/gdb | La plaga Tux

  41. Worked Like a Charm !! Thanks for this excellent guide..!

  42. Christian Fuchs says:

    Is there a possibility to configure Eclipse such that on compile, both Intel and ARM binaries are generated? Or alternatively, is it possible – via single mouse click – to select the target?
    I ask because I develop under Intel Linux and want to transfer binaries to the Raspberry only when I want to use the Raspberry for testing.

  43. Pingback: Hello, kernel! Part 2 | Raspberry Pi Kernel Development

  44. Pijus chanda says:

    Thank you for this great tutorial. But I face a problem when using includes of packages installed on the pi. In my case I have installed the mysql package on the pi. In my C++ program I need to include statements like #include “my_sql.h”. Those include files are located on the pi in the directory “usrincludemysql”. Naturally the cross compiler on the Ubuntu cannot find the include file as it is not in one of the specified include directories.
    How to solve this Problem? Same issue will occure when linking I guess. The libraries are on the pi and not on the Ubuntu host system.

    I tried the RSE plugin to solve this problem.
    With the eclipse RSE plugin however, I can browse through the pi’s remote file system. But including a remote path in the include directories of the project (e.g. rse://192.168.1.77/home/pi?raspberry) sort of does not work. I can see the additional include during the compile step -I../rse://192.168.1.77/home/pi?raspberry. My header file I want to include in the C++ file (e.g. test.h) is located in the home directory on the pi (/home/pi/test.h). But the compiler says, it cannot locate “test.h”

    Does anyone know how to solve this problem. I don’t want to install the mysql package on the Ubuntu. The header files might be the same but the libraries are for x86 and not for the ARM. So this won’t work. Another way would be to copy all include and libraries form the pi to the Ubuntu filesystem. But then I might have other dependency problems.

    • halherta says:

      Pijus you could create an image file of your Raspbian SD card (using dd command), mount it to your Linux VM and include the libraries/include paths into your Eclipse project. I haven’t played with this yet but many others have. Also tak a look at this link and this one

  45. pgallagher69 says:

    I’ve checked and double checked everything… I’m getting Description Resource Path Location Type
    “Program “g++” not found in PATH Preferences, C++/Build/Settings/Discovery, [CDT GCC Builtin Compiler Settings] options C/C++ Scanner Discovery Problem”…

    Any ideas?

    • halherta says:

      Pgallagher69, Eclipse interprets PATHS very differently than most other applications. Try starting eclipse from the command line with a “eclipse &” command.

      • pgallagher69 says:

        Thanks for the Super Fast reply Halherta! I ran the command, and it said eclipse wasn’t installed. So I installed it…. The command then ran the java version of eclipse annoyingly… But, I then ran the Juno c++ version again and it now builds! Brill! Thanks!

  46. WDB says:

    I hope someone can help me!!
    I’m new to the cross compile information

    I have read the “how to” cross compile on a windows machine
    here

    http://www.raspberry-projects.com/pi/programming-in-c/compilers-and-ides/eclipse/programming-the-rpi-in-windows-using-eclipse

    and manage to get it right to compile “Hello World” and copy it to the PI and run it there
    I however fail to get the debugging right but this is not the question just background information

    So i decided to try the linaro toolchain since this is the official one

    I went through this tutorial but only did the Eclipse stuff as i have a windows machine
    which is the same as the previous tutorial I did just point to a different compiler and add your library path as explained.

    here is the error i get from the previous tut “hell_world.c” with the new toolchain
    //———————————————————————————————————————————–
    10:45:28 **** Incremental Build of configuration Debug for project Raspberry_Pi_V001 ****
    make -j4 all
    Building file: ../src/Raspberry_Pi_V001.c
    Invoking: Cross GCC Compiler
    arm-linux-gnueabihf-gcc -I”C:Cygwinoptcrossgcc-linaro-arm-linux-gneabihf-raspbianarm-linux-gnueabihfinclude” -I”C:Cygwinoptcrossgcc-linaro-arm-linux-gneabihf-raspbianarm-linux-gnueabihflibcusrinclude” -I”C:Cygwinoptcrossgcc-linaro-arm-linux-gneabihf-raspbianlibgccarm-linux-gnueabihf4.7.2include-fixed” -I”C:Cygwinoptcrossgcc-linaro-arm-linux-gneabihf-raspbianlibgccarm-linux-gnueabihf4.7.2include” -I”C:Cygwinoptcrossgcc-linaro-arm-linux-gneabihf-raspbianlibgccarm-linux-gnueabihf4.7.2finclude” -I”C:Cygwinoptcrossx-toolsarm-unknown-linux-gnueabiarm-unknown-linux-gnueabisysrootusrlib” -I”C:Cygwinoptcrossx-toolsarm-unknown-linux-gnueabiarm-unknown-linux-gnueabisysrootusrinclude” -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF”src/Raspberry_Pi_V001.d” -MT”src/Raspberry_Pi_V001.d” -o “src/Raspberry_Pi_V001.o” “../src/Raspberry_Pi_V001.c”
    cygwin warning:
    MS-DOS style path detected: C:UsersWouterworkspaceRaspberry_Pi_V001Debug
    Preferred POSIX equivalent is: /cygdrive/c/Users/Wouter/workspace/Raspberry_Pi_V001/Debug
    CYGWIN environment variable option “nodosfilewarning” turns off this warning.
    src/subdir.mk:18: recipe for target `src/Raspberry_Pi_V001.o’ failed
    Consult the user’s guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
    /opt/cross/gcc-linaro-arm-linux-gneabihf-raspbian/bin/arm-linux-gnueabihf-gcc: line 1: /opt/cross/gcc-linaro-arm-linux-gneabihf-raspbian/bin/arm-linux-gnueabihf-gcc-4.7.2: cannot execute binary file
    make: *** [src/Raspberry_Pi_V001.o] Error 126
    //———————————————————————————————————————————–
    then i decided to create a new “Hello_World.c” project and compile
    then i get this error

    //———————————————————————————————————————————–
    Invoking: Cross GCC Compiler
    arm-linux-gnueabihf-gcc -I”C:Cygwinoptcrossgcc-linaro-arm-linux-gneabihf-raspbianarm-linux-gnueabihfinclude” -I”C:Cygwinoptcrossgcc-linaro-arm-linux-gneabihf-raspbianarm-linux-gnueabihflibcusrinclude” -I”C:Cygwinoptcrossgcc-linaro-arm-linux-gneabihf-raspbianlibgccarm-linux-gnueabihf4.7.2include-fixed” -I”C:Cygwinoptcrossgcc-linaro-arm-linux-gneabihf-raspbianlibgccarm-linux-gnueabihf4.7.2include” -I”C:Cygwinoptcrossgcc-linaro-arm-linux-gneabihf-raspbianlibgccarm-linux-gnueabihf4.7.2finclude” -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF”src/Hello_linaro.d” -MT”src/Hello_linaro.d” -o “src/Hello_linaro.o” “../src/Hello_linaro.c”
    /bin/sh: -c: line 0: unexpected EOF while looking for matching `”‘
    src/subdir.mk:18: recipe for target `src/Hello_linaro.o’ failed
    /bin/sh: -c: line 1: syntax error: unexpected end of file
    make: *** [src/Hello_linaro.o] Error 1
    //———————————————————————————————————————————–

    • halherta says:

      WDB,
      I do not use windows ( I run only Linux (Fedora and Debian) on my PCs) anymore so I can’t try to reproduce what you are doing here. Having said that, I would try cross compiling the hello world program from the command line (DOS/cmd window) by typing something like “arm-linux-gnueabihf-gcc -Wall -o helloworld.exe helloworld.c”. If this compiles successfully, then your problem is not in the toolchain and is in eclipse. If it doesn’t then there may be a problem with the toolchain. If the problem is eclipse based you might be missing somethng in your settings.

      BTW you would need to add the toolchain’s bin directory to your PATH variable in windows in order for eclipse to detect the toolchain.

  47. Pingback: Developing for Raspberry Pi. | Cognosfera

  48. Peter says:

    Awesome, best tutorial I’ve seen, many thanks!

  49. Cristian Prado says:

    Thanks !!!!!!!!!!!!

  50. Hélio Mendonça says:

    Do you know if there is an easy way of creating a new RPi Eclipse project without having to always change the settings you mentioned (proper gcc/gdb/as programs, all the include and lib paths, etc.)? Some kind of template/wizard that could set all those things automatically.

    Regards and congratulations for all your tutorials.

    • halherta says:

      Helio, There is such a way. I learned about recently. I intend to update this tutorial with it soon. Basically when creating a new project in Figure 6, choose “cross gcc” instead of “linux gcc”. You will then be asked to locate the bin directory of your toolchain. That should be it .Eclipse will take care of everything else.

    • Valdir says:

      I aways copy and paste an existing project and change the names. I think this is the easier way.

  51. Thilina says:

    Awesome, simple. Thank you.

  52. Mouli says:

    Hi,
    The tutorial is excellent but I am getting two errors in my eclipse as
    1.Program “g++” not found in PATH.
    2.Program “gcc” not found in PATH.

    I am new to linux. Please help me in this.

    Thank you.

  53. halherta says:

    Mouli,
    Something is wrong with the process of adding the toolchain’s “bin” directory to the path. make sure that you add “export PATH=$PATH:$HOME/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin” to both the .bashrc and .profile files in your “/home/username” directory.

    In addition to this, try starting eclipse from command line….in bash go to eclipse folder and type “./eclipse”

  54. Pingback: Cross compile for Raspbian on Ubuntu (Eclipse) | marcsi.ch

  55. Taisto says:

    Hi,
    Thanks for the good instruction.
    I don’t know why but it was needed to choose “arm-bcm2708hardfp-linux-gnueabi” environment to create the suitable binaries. (guess something kernel version related matter)
    Anyway, it worked the sample program worked well.

    BTW, has anyone succeeded to compile with bcm2835 library?
    Though I tired with it, got the following error during compiling.

    Any ideas??

    – Eclipse Output –
    make all
    Building file: ../src/HelloRPi.c
    Invoking: Cross GCC Compiler
    arm-bcm2708hardfp-linux-gnueabi-gcc -I/home/pi/raspberrypi/usr/local/include -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF”src/HelloRPi.d” -MT”src/HelloRPi.d” -o “src/HelloRPi.o” “../src/HelloRPi.c”
    Finished building: ../src/HelloRPi.c

    Building target: HelloRPi
    Invoking: Cross GCC Linker
    arm-bcm2708hardfp-linux-gnueabi-gcc -L/home/pi/raspberrypi/tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/lib -o “HelloRPi” ./src/HelloRPi.o -llibbcm2835
    /home/pi/tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/../lib/gcc/arm-bcm2708hardfp-linux-gnueabi/4.7.1/../../../../arm-bcm2708hardfp-linux-gnueabi/bin/ld: cannot find -llibbcm2835
    collect2: error: ld returned 1 exit status
    make: *** [HelloRPi] Error 1

    Thanks in advance.

    • Taisto says:

      Some updates…

      bcm2835 library should be compiled on the Rapsberry Pi or the cross-compile environment…

      When compiled it on Raspberry PI and copied
      bcm2835.o and libbcm2835 on cross-environment, got the following error.
      Assuming needed to compile them on cross-compile environment.
      I’ll try it.

      Building target: RPiPeripheral
      Invoking: Cross GCC Linker
      arm-bcm2708hardfp-linux-gnueabi-gcc -L/home/pi/raspberrypi/tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/lib -o “RPiPeripheral” ./src/RPiPeripheral.o -lbcm2835
      /home/pi/raspberrypi/tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/../lib/gcc/arm-bcm2708hardfp-linux-gnueabi/4.7.1/../../../../arm-bcm2708hardfp-linux-gnueabi/bin/ld: error: RPiPeripheral uses VFP register arguments, /home/pi/raspberrypi/tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/lib/libbcm2835.a(bcm2835.o) does not
      /home/pi/raspberrypi/tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin/../lib/gcc/arm-bcm2708hardfp-linux-gnueabi/4.7.1/../../../../arm-bcm2708hardfp-linux-gnueabi/bin/ld: failed to merge target specific data of file /home/pi/raspberrypi/tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/lib/libbcm2835.a(bcm2835.o)
      collect2: error: ld returned 1 exit status
      make: *** [RPiPeripheral] Error 1

  56. Kaushik Shrestha says:

    I am getting follwoing error on building project on eclipse console:

    make all
    Building file: ../HelloRpiWorld.cpp
    Invoking: Cross G++ Compiler
    arm-linux-gnueabihf-g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF”HelloRpiWorld.d” -MT”HelloRpiWorld.d” -o “HelloRpiWorld.o” “../HelloRpiWorld.cpp”
    Finished building: ../HelloRpiWorld.cpp
    Building target: HelloRpiWorld
    Invoking: Cross G++ Linker
    arm-linux-gnueabihf-g++ -o “HelloRpiWorld” ./HelloRpiWorld.o
    arm-linux-gnueabihf-g++: fatal error: -fuse-linker-plugin, but liblto_plugin.so not found
    compilation terminated.
    make: *** [HelloRpiWorld] Error 1

    Please someone help me !!

  57. JK says:

    Excellent work!!

  58. Pingback: Eclipse gtkmm cross-compiling for Raspberry Pi, can't find file ft2build.h even though it does exist | BlogoSfera

  59. Mark says:

    Thank you, this blog and your responses in the comments have been ridiculously helpful!

  60. Sanjana says:

    Thank you so very much for this tutorial…it helped me a lot… but before you install Eclipse please make sure that you have Java run time environment (JRE) installed and updated to the latest version and gcc compiler also installed…these are basic requirements for installing Eclipse for C/C++ developers.. And since i was remote cross debugging Windows PC to Raspberry Pi i had used the following links initially
    http://www.raspberry-projects.com/pi/programming-in-c/compilers-and-ides/eclipse/programming-the-rpi-in-windows-using-eclipse
    http://www.raspberry-projects.com/pi/programming-in-c/compilers-and-ides/eclipse/create-new-eclipse-project-for-the-rpi
    http://www.a2p.it/wordpress/tech-stuff/development/remote-debugging-raspberrypi/

    …..and to install JRE and gcc you can visit the following links
    http://www.youtube.com/watch?v=ZXI2zNKd1kI

    • halherta says:

      Sanjana, Thanks for the comments and the links. I highly recommend to those that really want to learn how to use the RaspberryPi to install Linux on their PC directly or in a virtual Machine. This will help you learn Linux/Raspbian. Its also much easier to have the RPi & PC communicate when the PC is running Linux.

      Personally I now run Linux only on my PC & laptop and have never looked back to my MS windows days. I don’t necessarily dislike MS windows. I simply prefer Linux!

      For beginners I recommend Kubuntu. For intermediate Linux users, have a look at Debian & Crunchbang Linux.

  61. Andrew says:

    Thank you for this wonderful tutorial! I was looking for something like this but never expected to find anything so detailed and accurate. The screenshots are great and the text follows them perfectly. What a nice piece of work!

    For anyone who is using Fedora 19 64-bit, you *may* need to run
    sudo yum install libstdc++.i686 zlib.i686
    to get these 32-bit libraries.

  62. giaoduong says:

    I have installed GCC sucessfully, but when i started eclipse, there was no Cross GCC available to choose?
    Where i can find it?

    • halherta says:

      Did you download the correct version of eclipse ? I recommend using eclipse Kepler for c/c++ development

      • giaoduong says:

        Thanks for your super fast answer, I downloaded the Eclipse Editor from your given link, the point is I already installed Eclipse before, But i still downloaded it again and when i created a C++ project, I couldn’t find the toolchain ????

        • giaoduong says:

          I did uninstall the Eclipse downloaded by the apt-get command, when I start the “~/eclipse/eclipse &”
          The terminal reply : cannot execute binary file
          Plz tell me what’s wrong with this ????

      • giaoduong says:

        I did uninstall the Eclipse downloaded by the apt-get command, when I start the “~/eclipse/eclipse &”
        The terminal reply : cannot execute binary file
        Plz tell me what’s wrong with this ????

  63. giaoduong says:

    Thanks God finally I did it, I can see my Cross GCC, but another problems is I couldn’t do this step :

    Locate the HelloWorld Binary file on our local desktop PC and drag it to the home directory on the Raspberry Pi (You could also right click on the binary and click on “Copy” and then right click on the home folder in the Raspberry Pi and click “Paste”. This effectively copies the binary file to the home directory of the Raspberry Pi.

  64. Girish Shah says:

    I follow your link but i am getting error

    -sh: ./HelloWorld not found,

    if i cross compile by using arm-linux-gnueabihf-gcc HelloWorld HelloWorld.c -static , It’s working fine.

  65. Jay says:

    I successfully cross-compiled a simple hello-world.c program for Raspberry Pi Board on my Ubuntu 12.04 host machine by following the instructions given in the post.

    The cross compilation command used was

    arm-linux-gnueabihf-gcc hello-world.c

    I executed the a.out thus generated on the Rasperry Pi board and it displays the correct output.

    Next I did
    ldd a.out
    and got the following result

    ldd a.out
    /usr/lib/arm-linux-gnueabihf/libcofi_rpi.so (0xbcfcb000)
    libc.so.6 ==> /lib/arm-linux-gnueabihf/libc.so.6 (0xb6e91000)
    /lib/ld-linux-armhf.so.3 (0xb6fd8000)

    Now, I am unable to find the file libcofi_rpi.so on my host Ubuntu 12.04 machine. So I am wondering how did the hello-world program get cross compiled in the first place. If I rename the libc.so* cross compiler arm libraries on the host Ubuntu 12.04 machine, the cross compilation fails. So I know, the cross compiler is definitely looking for these libraries. How then did the cross compilation succeed without the libcofi_rpi.so library on the host Ubuntu 12.04 machine?

    • halherta says:

      Jay its very likely that the file that you are looking for is found in the toolchain directory (sysroot) and the directories above are relative paths that exist within the relative paths.

      Remember in order for the a.out binary to execute on an ARM machine any library that its linked against must’ve also be an ARM based library….the build process should be completely independent of any x86 libraries found in the traditional locations (/usr/lib e.t.c)

  66. sakib says:

    Hi, Hello world or printing something works fine. But I can not access GPIO pins. to access the usb and GPIO pins do i need include some libraries? Also can not cross compile that’s written using wiringPi or without wiringPi (written completely in C/C++). also another new problem. As i included libraries and included the paths of here and there it’s is not generating the binary file :(

    • halherta says:

      Sakib, you can cross compile code that access the GPIO using sysfs (/sys/class/gpio/export e.t.c.) then move binary to raspberry pi and run it there. You will have to run the binary as root though because gpio access requires root permission. As for Wiring Pi, it would have to be built from source using the cross compiler and then linked appropriately on the PC in order to be used in a cross development environment. I haven’t done it myself…but it shouldn’t be that hard to do.

  67. Kaushalyas says:

    Hi, This was an excellent starting point for me and my Raspberry Pi. Thank you heaps.

    I could get the simple program compiled, but when I check ‘file HelloRPiWorld.o’ it reports ”ELF 32-bit LSB relocatable, ARM, version 1 (SYSV), not stripped’.

    How can I build this as executable?

    Thanks again,
    kaushalyas

    • Kaushalyas says:

      Hi,

      My apologies – I found out my (rather stupid) mistake. Its the object file I am trying to look at (HelloRPiWorld.o) instead of the linked file.

      Cheers,
      kaushalyas

  68. Anto says:

    Great! It worked flawlessly!
    thanks!

  69. Dave says:

    Seem to have an error.. when I try to get the gcc version info I get: “arm-linux-gnueabihf-gcc -v”
    “The program ‘arm-linux-gnueabihf-gcc’ is currently not installed. You can install it by typing: sudo apt-get install gcc-arm-linux-gnueabihf”

    I serarch the
    “~/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin$”
    and I don’t see “arm-linux-gnueabihf-gcc”

  70. Dave says:

    Update… I corrected the initail problem typo… duh

    Now I get an error attemptng to compile the simple “Hello World” cpp . It can’t resolve the ‘user namespace std’ and ‘cout’

  71. Julian says:

    A really good, easy to follow tutorial.
    Thank you

  72. Saurabh Patel says:

    I tried with steps you mentioned to setup cross compilation and it was working before my Ubuntu crash.I repeat all step again but this time i getting problem. Hope you can solve it.
    I downloaded the copy of tools of raspberry and then browse in the directory and run the command as you mentioned

    ~/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin$ arm-linux-gnueabihf-gcc -v

    and the answer is
    bash: /usr/bin/arm-linux-gnueabihf-gcc: No such file or directory
    May i know what i missing??
    Please response..!!!

    • halherta says:

      Saurabh, make sure that the toolchain and all of its binaries still exist by cding into that directory.Inspect the .bashrc file and ensure that the path variable includes the directory containing the cross compiler binaries. Finally try reinstalling ia32-libs if you are using a 64-bit OS i.e. ‘sudo apt-get –reinstall install ia32-libs’

  73. Saurabh says:

    Hi Halherta,
    I resolve that problem and still don’t know what problem i was facing. I had look in to directory and found that all relevant files were exists.

    As you suggested, to reinstalling ia32-libs and that might be a reason because i did that, even i downloaded fresh “tool” copy and started from first step.

    Anyways, thanks for the reply, keep replying!! :-)

  74. Aditya L says:

    I followed this guide to install development environment for raspberry Pi on ubuntu 12.04 64-bit LTS. I tried to crate a new C++ project in Eclipse Kepler as per the instructions. But I am not able to find “Cross GCC” option under Toolchain tab. What should I do for this?

    • halherta says:

      Aditya L …If you go to “File’ -> “New C++ project” the “Cross GCC” option should be there. You need to be using Eclipse for C/C++ developers…any other kind i.e. classic or java development will require additional plugins. Also I just tried setting up a new project in the kepler version of Eclipse for C/C++ developers and had no problems. My guess is you either downloaded the wrong version of Eclipse or have more than one Eclipse IDEs installed on your machine and are inadvertently opening the wrong one. I highly recommend that you start Eclipse from the terminal as per the instructions to ensure that you are using the correct version.

  75. Stig Hansen says:

    Excellent tutorial, easy to follow. Well done, thanks .

  76. Clive says:

    Hi,
    I able to cross-compile windows to raspberrypi using eclipse. But i cannot seem to be able to setup eclipse to use the WiringPi Libraries. wondering if you could do another of your wonderful tutorials, thanks

    • Neil H says:

      I needed to build the wiringPi library on the host system using the cross platform tools. While I build my applications in Eclipse, I built the wiringPi library at the command line.

      You may recognize much of this from the “Plan A” install from wiringpi.com. The only real difference is the specification of the compiler in the Makefiles.

      1. Install GIT: sudo apt-get install git-core
      2. Obtain wiringPi using GIT: git clone git://git.drogon.net/wiringPi
      3. We will now modify the Makefiles to use the ARM tools: We will modify the Makefiles in:
      a. wiringPi/devLib
      b. wiringPi/examples
      c. wiringPi/examples/Gertboard (optional)
      d. wiringPi/examples/PiFace (optional)
      e. wiringPi/examples/PiGlow (optional)
      f. wiringPi/examples/q2w (optional)
      g. wiringPi/gpio
      h. wiringPi/wiringPi
      4. Make the following change in the Makefiles:
      a. Comment out the line that reads “CC = gcc” (put a # in the 1st column to make the line into a comment)
      b. Add a new line just under the old “CC =…” line that reads “CC = arm-linux-gnueabihf-gcc”
      c. those two lines now look like:
      i. “#CC = gcc”
      ii. “CC = arm-linux-gnueabihf-gcc”
      d. Repeat for the other Makefiles.
      e. For ~/wiringPi/devLib/Makefile, find the line that reads “INCLUDE = -I.” and add ” -I/usr/local/include” to the end. The line now reads “INCLUDE = -I. -I/usr/local/include”.
      5. Return to the ‘top’ wiringPi directory: cd ~/wiringPi
      6. Insure that the build script is executable: chmod +x build
      7. Clean files built with other tools: ./build clean
      8. Build with the cross-development tools: ./build
      9. Now it’s time to tell your Eclipse projects about the wiringPi files in /usr/local/include and /usr/local/lib as if you were building on target: In the project properties:C/C++ General:Paths and Symbols, add /usr/local/include to GNU C/C++ in the include tab, and /usr/local/lib in the library search directory tab. Also, add wiringPi in the Libraries list under the Cross G++ Linker.

      Hope that helps.

  77. Lionel says:

    Hi, i’m using ubuntu 13.10 and i have followed these instructions but when i compile my helloworld first projet, i have this error

    Building target: HelloWorld
    Invoking: Cross G++ Linker
    arm-linux-gnueabihf-g++ -o “HelloWorld” ./src/HelloWorld.o
    arm-linux-gnueabihf-g++: fatal error: -fuse-linker-plugin, but liblto_plugin.so not found
    compilation terminated.
    make: *** [HelloWorld] Error 1

    18:21:06 Build Finished (took 969ms)

    I need to solve this problem because it’s the most important for my projet.

    i need your help

  78. mihai says:

    Very helpful. Thanks for putting this info here.

  79. Alejandro says:

    Thank you very much for this post, it’s amazing.

    I were stuck on the “Build project” step, I got the following error: “liblto_plugin.so not found”.
    I solved it by updating the toolchain to its newer version. Since I have done the “git checkout HEAD~1″ step, I had to do “git checkout master” to update it to the newer version.

    So, probably, it would be better to readjust the tutorial with a newer update on the “git checkout HEAD~1″ step.

    Thank you again,
    Alejandro.

  80. Neil H says:

    Thank you so much for your wonderful cookbook approach to cross development for RPi. I’m running Debian 7.4.0 in a VirtualBox under Win-7. Thanks to your clear directions, screen shots, and your hard work, I’m up and running 1st try! Next up is your post on Remote Debugging! Thanks again!

  81. Gary Rubin says:

    Terrific tutorial that teaches so much more than just the subject focused on. Running Debian 7.4.0 amd64 in VMware Player under Windows 7 64 bit 8 GB on an I5 2450M 2.50 MHz. This worked for me the very first time and has really opened up a lot of locked doors for me. Well written, illustrated, and thought out. A really awesome contribution and I thank you!!

    Only bug I noticed was the hello world file name changed here and there but anyone reading that is this deep into compiling would realize it and adjust.

    Now all I need to do is figure out how to use the Boost libraries. There is a version compiled for arm with hardware float which is what I need, but unclear where to put them, or how to link them. Googling now. I would love to see a tutorial about how to do that with ANY 3rd party library, branched off of this tutorial. =) Thanks again!!

    • halherta says:

      Gary, take a look at sshfs and nfs. They allow you to mount the RPi’s file system into a folder on your Linux PC over the network. Once this is established you can use the cross compiling toolchain in conjunction with the libraries on the mounted RPi root filesystem to cross compile applications for almost any library (libboost, libwt, libcurl, libopencv libgtkmm and many more). Tools like cmake & make can facilitate this process. I’m planning to try this real soon and possibly write a tutorial on it in the near future.

      Have a look at this: http://redmine.emweb.be/projects/wt/wiki/Cross_compile_Wt_on_Raspberry_Pi

      • Gary Rubin says:

        This is brilliant halherta! I would never have imagined this possible! I am stuck though, as I went to the link you posted, and after a bit of permission/group work, I was able to mount the RPi file system to a mount point as a user (not root). I even copied some code from it to the root of my home folder without any issues.

        What I am stuck on, again, in the link you posted, after mounting the RPi’s file system is where they mention a second set of links…

        Imporant note: on the raspbian distribution we used, we ran into a second form of ‘links’ to absolute paths that prevented linking to work out of the box (resulting in link errors for libpthread, libc, libc_nonshared, …). The files /usr/lib/arm-linux-gnueabihf/libc.so and /usr/lib/arm-linux-gnueabihf/libpthread.so are actually linker scripts that refer to absolute paths, which are not correct when cross compiling. Our solution was to remove the absolute path from the linker script.
        The two files they recommend editing to remove the absolute paths… are they on the RPi or my host?

        • halherta says:

          Gary, I haven’t tried this yet, but they should be on the RPI. By the way Wt is a great C++ web development framework bsed on the Qt philosophy

      • Gary Rubin says:

        I went through the link you posted halherta and made a cmake file, but not sure where to go from here, with Eclipse anyway. It’s getting late and the wife is getting antsy, so I’ll close the laptop up for the night and hit the ground running tomorrow morning. Please post anything new you discover and I certainly hope you write a tutorial for what we are doing now. These are some really neat things we are exploring! Cheers!

      • Gary Rubin says:

        OK, I tried a number of things in Eclipse and got close, but not close enough. I continued to have problems with duplicate definitions, and always a problem with “lib(my project name).so” as in “libsbec.so”. I’m absolutely sure it is how I am telling Eclipse to look for the other libraries. I know very little about the tool settings and what to put where as far as compiler and linker flags. I thought I had it right when I reduced the compile down to one error, but it was the one I mentioned above, and the output showed the flags I put in (from another tutorial) as unknown.
        I am now copying the usr folder from the Pi to my guest OS, to a sub directory in my user’s home folder. I will then take baby steps, adding one include at a time and testing other tool settings configurations. I need to learn what the flags mean in G++ anyway.

  82. Gary Rubin says:

    I got it finally halherta. I copied the usr directory and its contents to the guest OS, into a sub directory of home. In Eclipse under C/C++ Build / Environment, I added the directory to the path variable ‘/home/user/rpi_usr’, under Cross G++ Linker / Libraries I added “boost_system-mt” to the “Libraries (-L)” list, and under Cross G++ Linker / Miscellaneous I entered “-L/home/hop/rpi_usr/lib -lboost_system -lpthread -lm” into the “Linker flags” field. I compiled and no errors, but a bunch of warnings. 140 of them but all warned that had something like "typedef ‘boost_concept_check103’ locally defined but not used [-Wunused-local-typedefs] sbec_pi". I copied the binary to the Pi but the system would not let me chmod -x it. The executable flags just wouldn’t set and I have no idea why. I just used chmod 777 on it and it ran just fine!!! YIPPEE!

    So I want to get rid of the warnings, and figure out why I couldn’t use chmod -x to make it executable, but I’m there with boost libaries!! I can’t tell you how grateful I am halherta for the pushes in the right direction! THANK YOU!!! =D

    • halherta says:

      Gary I’m glad that you were able to cross compile with the lib boost in the end! I’m not sure about the warnings but to give a file (say “binary”) global executable permissions you need to do something like “sudo chmod +x binary”. “chmod -x” I believe makes files non-executable….it’s an exception to the standard GNU/POSIX/UNIX flag rules.

      • Gary Rubin says:

        Oh wow, after all I have done and been through, and I made that simple mistake. Had to be all the “-” I have been typing and retyping for flags. That’s just too funny!

        Thanks for pointing that out! That behavior might have stuck. =O

  83. RolfOz says:

    Just started.. Is all this working for the Rpi recommended “New Out Of Box Software” (noobs) as well, or is it better to stick with a Raspbian Wheezy??

    Thanks,
    Rolf

    • halherta says:

      RolfOz, This works on Raspbian Wheezy. I’ve never tried NOOBS. but my understanding is that NOOBS is basically a multiboot setup i.e. you can use it to boot into Raspbian, Fedora Raspbmc e.t.c. So my guess is that this will work with NOOBs if you use it to boot into Wheezy. Let me know how it goes

  84. Rohit says:

    Hi,

    The article is great!!

    Thanks You,
    Rohit

  85. Aditya Gandhi says:

    Thanks for the tutorial!

    I think in the latest version of Ubuntu 14.04 they have deprecated the package lib32asound2, I am not sure why is this needed for with respect to gdb. Is it okay to not install it?

    • halherta says:

      Aditya, you’ll probably be OK without it! I haven’t installed the Ubuntu 14.04 yet (I’m waiting for Elementary OS release!) but I will update it when I do. In the meantime please report back if things worked without lib32asound2 and I’ll update the blog accordingly.

      • Aditya Gandhi says:

        So I tried the debugging , Hello World programs works good, I set it up a bit different, I use the gnu arm eclipse plugin for GCC, and the Automatic debug server launcher for pi (After manually copying the gdbserver for pi on target). I am facing issues with debugging a Small program to communicate over nrf24l01+ modules, it says cannot access memory at 0×0 while trying to debug, I am not sure what’s up with that. I am going to redo everything with the steps you mentioned.

        • halherta says:

          Aditya..you definitely should not use the gnu arm eclipse plugin for GCC..that plugin is intended for use for bare metal development of ARM Microcontrollers…not ARM microprocessors running Linux as is the case with the RPi.

          I do not like Automatic Debug….it saves us from having to type a single command on the RPi (to start gdb server) at the cost of requiring that Eclipse have root privileges on the RPi…..not a big fan of that.

  86. Matteo Taccola says:

    Thank you very much. Very useful!!

  87. ozarchie says:

    Thankyou very much.
    An excellent tutorial – well structured and every stage worked for me.
    I installed on a 32-bit Ubuntu 12.04LTS machine.
    You have saved me a great deal of time and effort.
    I am developing some extensions to USBIP and hope to be able to return the favour to other members of the Raspi community.

  88. Olfat says:

    Hello,

    This is look great i think it is very helping thank you. but i have a different question if you can help me with. I’m trying to collect some info from raspberry pi using streamline came with DS-5. I’m currently trying to figure a way to create gator and deamon but i noticed that raspberry pi is not recognized with the adb devices command. also it is not supported by Arm ds-5 but the arm 11 is supported.
    MY question is how to use it with streamline how to create the deamon and gator?
    thanks

  89. Igor says:

    Installed according the tutorial I am getting weird error:

    Ubuntu 12.04 LTS 64-bit

    Program:

    #include
    int main(void)
    {
    printf(“Hello world!\n”);
    return 0;
    }

    Result:
    10:35:18 **** Build of configuration Debug for project HelloRPiWorld ****
    make all
    Building file: ../HelloRPiWorld.c
    Invoking: Cross GCC Compiler
    arm-linux-gnueabihf-gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF”HelloRPiWorld.d” -MT”HelloRPiWorld.d” -o “HelloRPiWorld.o” “../HelloRPiWorld.c”
    Finished building: ../HelloRPiWorld.c

    Building target: HelloRPiWorld
    Invoking: Cross GCC Linker
    arm-linux-gnueabihf-gcc -o “HelloRPiWorld” ./HelloRPiWorld.o
    /home/ipokorny/rpi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/../arm-linux-gnueabihf/libc/usr/lib/arm-linux-gnueabihf/crt1.o: In function `_start’:
    (.text+0×34): undefined reference to `main’
    collect2: error: ld returned 1 exit status
    make: *** [HelloRPiWorld] Error 1

    10:35:18 Build Finished (took 209ms)

    Objdump shows the .0 file is empty, there is really no symbol main

    objdump -t HelloRPiWorld.o

    HelloRPiWorld.o: file format elf32-little

    SYMBOL TABLE:
    00000000 l df *ABS* 00000000 HelloRPiWorld.c
    00000000 l d .text 00000000 .text
    00000000 l d .data 00000000 .data
    00000000 l d .bss 00000000 .bss
    00000000 l d .debug_info 00000000 .debug_info
    00000000 l d .debug_abbrev 00000000 .debug_abbrev
    00000000 l d .debug_aranges 00000000 .debug_aranges
    00000000 l d .debug_macro 00000000 .debug_macro
    00000000 l d .debug_line 00000000 .debug_line
    00000000 l d .debug_str 00000000 .debug_str
    00000000 l d .note.GNU-stack 00000000 .note.GNU-stack
    00000000 l d .debug_macro 00000000 .debug_macro
    00000000 l .group 00000000 wm4.1.fdf68d773ae72d17c9370dac96e82d4a
    00000000 l d .comment 00000000 .comment
    00000000 l d .ARM.attributes 00000000 .ARM.attributes
    00000000 l d .group 00000000 .group

    I tried gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/ as well as gcc-linaro-arm-linux-gnueabihf-raspbian/bin/ with the same result.

    Any idea?

  90. Igor says:

    I discovered when I make a directory inside the project and put source file into everything is OK… Hmm… strange, but it works :-)

  91. Pingback: Cross compilling – raspberry pi | Priestor používateľa Vladimir

  92. linsong says:

    Thanks a lot, it all works!! The only thing different from my system is that I used the gcc-linaro-arm-linux-gnueabihf-raspbian-x64.

  93. Ricardo says:

    I was getting segmentation fault on a simple hello world. My problem was that before follow this tutorial, I had installed gcc-arm-linux-gnueabihf with apt-get.
    just type:
    sudo apt-get remove gcc-arm-linux-gnueabihf

  94. HelloRpiWorld says:

    halherta,. you are a legend,.. this was the only tute I could find that didn’t assume the reader was familiar with Linux,…… I’m not,.. so this was a great help. Can’t wait to read some of your other posts.

    thanks

  95. Pingback: Kerry D. Wong » Blog Archive » Compiling and Running EnOcean Sensor Kit Example Code

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>