Author Topic: How to set up cross-compilation for Raspberry PI?  (Read 26048 times)

Offline cacb

  • Regular
  • ***
  • Posts: 389
How to set up cross-compilation for Raspberry PI?
« on: January 21, 2014, 08:37:19 pm »
Hi,

I use C::B under Windows, Kubuntu and now also Raspbian. I am able to run C::B and compile on the Raspberry PI, but the process is extremely slow. So I would like to explore how to do cross compilation from either Kubuntu or Windows.

My projects already include build targets using the gcc compiler, essentially my projects can be copied from linux and to the PI and they work fine. But if I want to cross-compile from linux , how can I tell C::B to use the cross-compiler rather than the local gcc for linux ? Essentually, I would like to test and debug under linux, and when things work simply switch to the cross-compilation compiler and build for the Raspberry PI, using the same project and build target. Can this be done in a simple way?

A clever solution would maybe be to use global variables to define what "gcc" pointed to, but is something like that supported?
Another option is perhaps cross compiling to the PI from Windows, as I am not using the gcc compiler on windows, but it feels a bit odd to have to do it.

Any tips? I have checked the wiki, but not found clear answers.



Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: How to set up cross-compilation for Raspberry PI?
« Reply #1 on: January 21, 2014, 09:05:43 pm »
What's wrong with having two (or more) targets (e.g. linux, pi, windows) ?
Switching between targets is not really so hard  ;) .
And using different global vars just to switch between compilers is much more complicated and probably error-prone (dangling object files etc).

Offline cacb

  • Regular
  • ***
  • Posts: 389
Re: How to set up cross-compilation for Raspberry PI?
« Reply #2 on: January 22, 2014, 12:08:14 am »
What's wrong with having two (or more) targets (e.g. linux, pi, windows) ?
Switching between targets is not really so hard  ;) .
And using different global vars just to switch between compilers is much more complicated and probably error-prone (dangling object files etc).

Well, it is "wrong" because they would be identical except for the variant of gcc compiler used and "intrusive" in my project files. Anyway, It was my thought that I didn't want yet another set of build targets in my projects (I have quite a few project files).

But it seems I have now found another way which looks acceptable to me (less intrusive):

1. Install vmware or similar with your favourite linux distro.
This becomes a dedicated cross-compilation computer.

2. Get the raspberry pi cross-compiler toolchain
Follow http://jeremy-nicola.info/portfolio-item/cross-compilation-distributed-compilation-for-the-raspberry-pi/

Quote
sudo apt-get install git-core
git clone https://github.com/raspberrypi/tools.git --depth=1
(did this under a new main folder "/pi")

2. Install code::blocks  (it may complain no compiler detected)

3. Configure "GNU GCC compiler" using the raspberry PI cross compiler
Settings -> Compiler... Toolchain executables
Compiler's Installation directory:  /pi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian
Quote
C compiler               : arm-linux-gnueabihf-gcc
C++ compiler             : arm-linux-gnueabihf-g++
Linker for dynamic libs  : arm-linux-gnueabihf-gcc
Linker for static libs   : arm-linux-gnueabihf-ar

This works at least for simple things. I guess it is a matter of preference, but this way my project files are completely untouched, same build target used for raspbian as any other linux distro.

Next is to figure out how to build wxWidgets using this toolchain.

GrubbyHalo

  • Guest
Re: How to set up cross-compilation for Raspberry PI?
« Reply #3 on: July 07, 2014, 01:12:25 pm »
Hi cacb. Did you manage to cross compile wxWdigets3.0 for the pi

Regards
Grubby

Offline cacb

  • Regular
  • ***
  • Posts: 389
Re: How to set up cross-compilation for Raspberry PI?
« Reply #4 on: July 14, 2014, 01:06:36 am »
Hi cacb. Did you manage to cross compile wxWdigets3.0 for the pi

Regards
Grubby

Hi Grubby,

No, the setup was too complex for me. I have instead compiled wx3.0 directly on the PI itself. It takes a long time but it is easier.