JMak
Posts: 6
Joined: Fri Dec 28, 2012 10:25 pm

Qt or GTK on Raspian Wheezy

Thu Feb 14, 2013 7:27 pm

I've been digging through hundreds of forum posts, google search results, and tutorials and I've met nothing but frustration when trying to spin up a simple gui on the raspberry pi. I've installed the latest Raspbian Wheezy image located here http://downloads.raspberrypi.org/images ... spbian.zip.

I've followed various tutorials and instructions to create a simple hello world gtk app and I've been met with failures along the way. The biggest is that it seems the gtk libs and headers are in a location that gcc isn't configured for. I've tried adding a -I flag to gcc to the gtk libs but then I get bunch of other errors with various other headers. After running down that rabbit hole for a couple of iterations I had the feeling that I was doing something wrong.

I gave up on gtk and tried to go the Qt route. I followed the instructions here: http://qt-project.org/wiki/apt-get_Qt4_ ... spberry_Pi and was met with failure at the Qtcreator step.

Is there any straight forward tutorial (I don't mind a bunch of steps as long as they work) for creating a simple GUI in C++ on the Pi? Yes, I know that raspbian is more oriented (and the Pi community in general) to Python, but my language of choice is C++ for various reasons.

That being said, I'm calling on any C/C++ gurus out there that can point me to some straightforward documentation on how to spin up a simple hello world program on the PI using C/C++ and preferably GTK. Qt is okay and if I have to drop down to X that's fine too. WxWidgets obviously includes Gtk and I'm not interested in the bloat that comes with it, so I'm not interested in any WxWidgets examples. I just want to see a window with a title bar, menu and a simple button that I can attach an event handler to. I'll take it from there.

One complication - I need whatever distro I use to be able to be used headless. That's why I'm using Raspbian Wheezy - it's quite easy to setup headless. I don't mind switching distro's, but it has to be able to be ran headless.

Thank you, in advance, for any constructive advice that furthers my goal of creating a GUI in C/C++ on the raspberry PI.

-rst-
Posts: 1316
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland

Re: Qt or GTK on Raspian Wheezy

Thu Feb 14, 2013 7:46 pm

Sounds like maybe you have not had the (Gtk) development libraries packages installed (and tried to compile against the runtime libs)?

In that case:

Code: Select all

apt-get install libgtk2.0-dev
Also you might want to elaborate on 'failure at the Qtcreator step' - what do you mean by that (error messages etc)?
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'

User avatar
PeterO
Posts: 5451
Joined: Sun Jul 22, 2012 4:14 pm

Re: Qt or GTK on Raspian Wheezy

Thu Feb 14, 2013 7:49 pm

JMak wrote:The biggest is that it seems the gtk libs and headers are in a location that gcc isn't configured for. I've tried adding a -I flag to gcc to the gtk libs but then I get bunch of other errors with various other headers. After running down that rabbit hole for a couple of iterations I had the feeling that I was doing something wrong.
It sounds like what you were doing wrong was not using pkg-config to set the include and link flags for gcc !

Code: Select all

[email protected] ~ $ pkg-config --cflags gtk+-2.0
-pthread -I/usr/include/gtk-2.0 -I/usr/lib/arm-linux-gnueabihf/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12  
[email protected] ~ $ pkg-config --libs gtk+-2.0
-lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lglib-2.0  
[email protected] ~ $ 

To compile a simple gtk "hello world" program use

gcc -o hello hello.c $(pkg-config --cflags gtk+-2.0) $(pkg-config --libs gtk+-2.0)

HTH

PeterO

PS: -rst- is right about installing the development libs and headers !
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

JMak
Posts: 6
Joined: Fri Dec 28, 2012 10:25 pm

Re: Qt or GTK on Raspian Wheezy

Fri Feb 15, 2013 1:53 am

To compile a simple gtk "hello world" program use

gcc -o hello hello.c $(pkg-config --cflags gtk+-2.0) $(pkg-config --libs gtk+-2.0)
That was it! I was finally able to compile. Thank you so much!

GrahamBriggs
Posts: 20
Joined: Wed Jun 05, 2013 6:42 am
Location: Corvallis, OR
Contact: Website

Re: Qt or GTK on Raspian Wheezy

Sun Jun 09, 2013 10:02 am

Can anyone help me, I have a similar problem, and this thread is the closest thing on the web to answering my question.

My environment:
Using latest Eclipse Juno on latest Ubuntu 12 via parallels running on mac

My project:
A simple hello world written in C++ to be deployed to the RPi. I also have a build to deploy to the Ubuntu machine for testing (remote debugging always adds more problems when you are getting started). I want to create some simple UI using GTK, and I have implemented the first gtk tutorial to show a simple window.

I followed the threads and I have added the $(pkg-config --cflags --libs gtk+-3.0) to the command line pattern for the compiler and linker. I also had to add all the include files listed by the pkg-config --cflag command line, similarly, I added all the libraries listed by the --libs command line.

I am able to get this program to compile and run in a debug configuration on Ubuntu. However, when I try to compile and deploy to the RPi, I get this:

Code: Select all

/home/gbriggs/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.7.2/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lgtk-3
/home/gbriggs/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.7.2/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lgdk-3 
...
With two of these error lines for each of the 11 libraries the pkg-config told me to add.

Followed by this:

Code: Select all

collect2: error: ld returned 1 exit status
I suspect that the issue is that when doing the build for RPi (setup according to instructions from hertaville.com) the arm-linux-gnueabihf-g++ compiler can not find the libraries that the stock g++ compiler can?

Does anyone know how I can configure Eclipse to do a Raspberry Pi build using simple GTK objects.


Thank you

GB

ibex77
Posts: 2
Joined: Sun Jun 09, 2013 1:57 pm

Re: Qt or GTK on Raspian Wheezy

Sun Jun 09, 2013 2:12 pm

Hallo

I have a similar problem with gtk.
Trying to compile a csharp code using the reference libraries "system" and "gtk" into an exe.
Using the mono compiler:
sudo mcs Program.cs /r: System.dll, gtk.dll
But I get a compiler error: gtk not found.
even "apt-get install libgtk2.0" already done...

Any idea how can I compile the csharp code using mono?
Many thanks for your support!

halhertani
Posts: 40
Joined: Sun Aug 19, 2012 5:02 am
Location: Ottawa, ON Canada
Contact: Website

Re: Qt or GTK on Raspian Wheezy

Wed Apr 16, 2014 10:23 am

I managed to successfully cross compile GTK+ 3 & QT4 applications for the RPi on my PC. My approach in both cases is purely makefile based i.e. i.m not using pkg-config nor qmake....

Because the projects are makefile based you can easily import them into Eclipse as Makefile projects...or do what I do and use vim and/or geany for code editing and build/debug from command line. My approaches are documented in the links below.

Cross compiling GTK+ 3 apps for the RPI: http://hertaville.com/2013/07/19/cross- ... pberry-pi/

Cross compiling QT4 apps for the RPI: http://hertaville.com/2014/04/12/cross- ... g-qt4-app/

xpeace
Posts: 8
Joined: Fri Sep 05, 2014 11:19 am

Re: Qt or GTK on Raspian Wheezy

Fri Sep 05, 2014 12:02 pm

I went for GTK - I work on a Windows PC Eclipse crosscompilation environment.

I can build the Pi binaries on the Windows Pc and debug them directly on the Pi. As I have a small tft touchscreen attached to the pi, I can see the gfx working immediately :)

As there is a GTK framebuffer plugin, binaries could also be run without the X overhead. ( I did not use this feature yet ).

Framebuffer support should work in QT5 as well (via plugin), but I have not been capable of creating an Easy to use developing Environment for using
Win crosscompile and qt5 for raspberry, ...

Greetz xpeace

Return to “C/C++”