Cross compile for Raspbian on Ubuntu (Eclipse)

For a project I’m working on, I’m developing a C++ application on the Raspberry Pi (Raspbian “wheezy”). I started working directly on the Rasppi but soon enough the compilation took really long to the point it wasn’t comfortable for me any more. So I decided to try to cross compile on my virtual Ubuntu on my computer. At the end this worked out pretty great, and I’m happy with the solution. I’m using Eclipse CDT as the IDE, which I’m not entirely happy about.

Most information about setting this up I found on the blog post from Hartaville. There are a few differences though. There is a step that makes the process a lot easier, and this isn’t mentioned in the blog itself, but only in the comments. So here I list the important broad steps:

  1. Download and Install Eclipse Juno
  2. Download Cross Compiling Toolchain ( https://github.com/raspberrypi/tools )
    • I put it into /home/shin/raspberrypi
  3. Creating new Project in Eclipse:
    1. File -> New -> C++ Project
    2. choose “Cross GCC” as the Toolchain. <- This is the one step that is different
    3. Rest is normal, until to the “Cross GCC Command” page
      • Cross compiler prefix: prefix: arm-linux-gnueabihf-
      • Cross compiler path: /home/shin/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin
    4. These steps should make sure that Eclipse will configure itself (include paths etc.)

This should be enough to cross compile a basic project. For my project I also needed to use libraries that aren’t available in the cross toolchain. The next steps is how I made it compile with these libraries included.

  1. Download & Compile & Install the libraries on the Raspberry Pi
  2. Find the library files. (usually in /usr/lib/ or usr/local/lib)
    • copy to the workstation:  /home/shin/raspberrypi/tools/usr/lib
  3. Find the include files (usually in /usr/inculde or usr/local/include)
    • copy to the workstation: /home/shin/raspberrypi/tools/usr/include
  4. Configure Eclipse: Project -> Properties -> C/C++ Build -> Settings
    • Cross G++ Compiler
      • Includes: -I: /home/shin/raspberrypi/usr/include
    • Cross G++ Linker
      • Libraries:
        • -l: thrift, wiringPi, boost_thread, pthread, gloox
        • -L: /home/shin/raspberrypi/usr/lib

In my project these options worked nice. I ran into the problem that the libraries itself needed other libraries included. In my case these were libcrypto, libssl and libz. With the following steps I included those:

  1.  Find the libraries on the Raspberry Pi
    • In my case, they were in usr/lib/arm-linux-gnuebihf/
    • copy to the workstation: /home/shin/raspberrypi/tools/usr/wl
  2. Configure Eclipse: Project -> Properties -> C/C++ Build -> Settings
    • Cross G++ Linker
      • Miscellaneous:
        • Linker flags: -Wl,-rpath-link,/home/shin/raspberrypi/usr/wl

Well, this worked for me anyway. I also set-up Remote Debugging. Just follow instructions the instructions in the blog post from Hartaville.

Edit: corrected the path of the cross-compiler. Thanks reader in the comments

Comments

  1. No, it doesn’t work either: no symbols are resolved, this tuto is just another fake.

    Same mess than your source hartaville which is also a huge pile of sh.t, with twice its length of comment saying that all fails!

    Do you SIMPLY verify, test and experience what you’re posting ?!?

    1. yes, I did. It worked for me. I go through the process again, this afternoon, and try to find what the problem is.

  2. The correct path for the given compiler prefix is:

    $HOME/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin

    No need to add all “path for dummies” bullshit in .profile or .bashrc as your source said.

    1. yes, thank you. that seems to be the correct path. Weirdly enough, the wrong path I had in my project, worked also.

      You are also correct about .profie, .bashrc. I never did that. It is not necessary.

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>

%d bloggers like this: