Monday, October 05, 2015

Cross Compile WxWidgets/C++ Application for Raspberry Pi

How to Build wxWidgets / C++ for Raspberry Pi Model 2 (ARMv7 Architecture). 


UPDATED:
For ease to install and configure Eclipse-IDE/Toolchain, use following link of ready used installer:

wxWidgets is an awesome C++/GUI library to work with. It can produce very nice desktop interface and has complete class library either for GUI on non GUI. Binary program yields by this library is also small and portable. Statically linking is possible to make the program running independently to any linux distribution.

Raspberry Pi is credit card sized computer, it has small form factor with capability similar to PC of PIII/900MHz with 1GB RAM. Thus, sufficient to running desktop application, as in his case, Raspbian Wheezy.

Here, you will find brief tutorial how to build wxWidgets for Raspbian to run on Raspberry Pi model 2 (ARMv7 processor).

Setup environment to used are:
  • Build system on Ubuntu 14.04 LTS x64
  • buildroot
  • wxWidgets-3.0.2
  • Target: RaspberryPi2 and Raspbian Wheezy

Build Toolchain for ARMv7

To build cross architecture Toolchain we can use awesome build system called buildroot (http://buildroot.uclibc.org/)

$ cd ~
$ mkdir wxWidgets
$ cd ~/wxWidgets
$ git clone git://git.buildroot.net/buildroot
$ cd buildroot
$ make raspberrypi2_defconfig
$ make menuconfig


Adjust some requirement as follow:

    Toolchain
    C library (uClibc) --->
    (X) glibc

    Target packages > Graphic libraries and applications
    [*] X.org X WIndow System --->

    Target packages > Libraries > Graphics
    [X] libgtk2

    [Save]

$ make

Build wxWidgets for ARMv7

Once above toolchain baked and cooked well, then we can start to build and compile wxWidgets and it’s sample application.

$ export PATH=~/wxWidgets/buildroot/output/host/usr/bin:$PATH
$ cd ~/wxWidgets
$ wget http://nchc.dl.sourceforge.net/project/wxwindows/3.0.2/wxWidgets-3.0.2.tar.bz2
$ tar -xzpvf wxWidgets-3.0.2.tar.bz2
$ cd wxWidgets-3.0.2
$ mkdir -p build_rpi2/wx3.0.2u_static
$ cd build_rpi2/wx3.0.2u_static
$ ../../configure --host=arm-linux --with-gtk --with-libpng=builtin --with-libjpeg=builtin --with-libtiff=builtin --with-regex=builtin --with-zlib=builtin --with-expat=builtin LDFLAGS="-static-libgcc -static-libstdc++"
$ make
 


Sit back and relax...... 

Build Sample Application

$ cd samples/minimal
$ make

Copy sample/minimal/minimal to Pi's sdcard and from there try to run: 
$ ./minimal

See the result ................

After adjusting some path as describe on buildroot manual, you can download ready  used Raspberrypi-Toolchain on sourceforge.net. The  toolchain already tested on Ubuntu 14.04 with wxWidgets-3.0.2 as target built. This toolchain can be used for compiling Plain C/C++ for Pi application.

5 comments:

FloatingCloud said...

Dear Dedy,

Please could you post the compiled wxWidgets 3.0.2 binaries for Raspberry Pi?

Best regards,
Ric.

Dedy Yasriady said...

Hi Ric,

Compiled wxWidgets 3.0.2 for Raspberry Pi could be found on this following link: https://github.com/dveltool/toolchain

Make a try and feedback your result, please.

Rgrds/Ddy

Unknown said...

Any idea why I'm getting the following error message when I run the app on my Pi? I've setup my environment as stated above.

./minimal: error while loading shared libraries: libwx_gtk2u_core-3.0.so.0: cannot open shared object file: No such file or directory

svchavan said...

Hi,
I'm new to Linux. I'm trying to install wxWidgets on raspberry Pi3 Medel B. Refer "Build Toolchain for ARMv7", you ask to make some adjustment Toolchain---->
I do not know how to do this? are there any Linux commands to do this?

Adjust some requirement as follow:

Toolchain
C library (uClibc) --->
(X) glibc

Target packages > Graphic libraries and applications
[*] X.org X WIndow System --->

Target packages > Libraries > Graphics
[X] libgtk2

[Save]

Unknown said...

I'd really like to get this working but am running into some issues. My environment is a little different but should still work.

Setup environment:
-Build system on Ubuntu 16.04 LTS x64
-buildroot
-wxWidgets-3.0.2
-Target: RaspberryPi3 and Raspbian Jessie

When I move the built file (minimal) to the pi and execute I get:

./minimal: error while loading shared libraries: libwx_gtk2u_core-3.0.so.0: cannot open shared object file: No such file or directory

I then installed the wxWidgets library with:
sudo apt-get install libwxgtk3.0-dev

Now I get:
./minimal: relocation error: ./minimal: symbol __cxa_call_unexpected, version WXU_3.0 not defined in file libwx_baseu-3.0.so.0 with link time reference

Any idea how to get this to run on a Pi3 running Jessie?