Cross-compiling GTK application in command line


I’m trying to compile a GTK application through command line/Makefile without using any IDE. I’ve followed several posts that does it with Eclipse setting cflags and libs variables but I’m unable to make it work.

At this point:

  • GTK Application compiles (and works perfectly) from/to the host machine setting the PKG_CONFIG_PATH to my local path and then launching pkg-config --cflags gtk±3.0 and pkg-config --libs gtk±3.0. Compilation command is: gcc `pkg-config --cflags gtk±3.0 -o GtkExample GtkExample.c \pkg-config --libs gtk±3.0`
  • I’ve generated my oe-core sdk in ~/SDK_Angstrom instead of leaving the default one.
  • My SDK generates pkg-config but I don’t find any gtk there so I’m guessing that it uses the same gtk…pc

After I’ve sourced ~/Angstrom_SDK/environment-setup-armv7at2hf-neon-angstrom-linux-gnueabi, I’ve tried the following commands:

1st try: Try to configure pkg-config flags with mine.

$ pkg-config --cflags gtk±3.0
This returns that the package gtk±3.0 is not found in the search path.

2nd try: Try to compile directly:

${CC} ${CFLAGS} -c --sysroot=/home/alvaro/Angstrom_SDK/sysroots/armv7at2hf-neon-angstrom-linux-gnueabi/ `/home/alvaro/Angstrom_SDK/sysroots/x86_64-angstromsdk-linux/usr/bin/pkg-config --cflags gtk±3.0` GtkExample.c -o GtkExample

This returns the same than the 1st with the addition if “gtk/gtk.h: No such file or directory”.

3rd try: Same commands but with gtk±2.0
Same results.

I’m guessing that it’s failing to get the include/libs for gtk for ARM from the SDK (which I’m unable to find). I also fail to understand if the .pc is the same because I don’t how by changing the pkgconfig path it does find the gtk pc in the Eclipse examples.

Thanks, Álvaro.


Could you double check that you really did build an SDK which installs the gtk+ libraries in the version you need.

An SDK built with ‘bitbake angstrom-lxde-image -c populate_sdk’ actually does provide the gtk±3.0.pc file and in one of the include paths provided with --cflags there is also the gtk/gtk.h file:

$ . environment-setup-armv7at2hf-neon-angstrom-linux-gnueabi 
$ which pkg-config 

$ pkg-config --libs gtk+-3.0
-lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0
$ pkg-config --libs gtk+-2.0
-lgtk-x11-2.0 -lgdk-x11-2.0 -lpangocairo-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lfontconfig -lfreetype

$ ls sysroots/armv7at2hf-neon-angstrom-linux-gnueabi/usr/include/gtk-3.0/gtk/gtk.h


Thanks Max. Lines 7 and and 12 report me an error so it seems that definitely something is wrong with my build.

Now that you mention it I’m unsure if my populate_sdk action was with the meta-toolchain-qt5… Could that explain it? Anyway, I’m rebuilding the environment (and is not using much from previous builds so it looks promising).

I’ll report any updates asap, thanks again! :slight_smile:

EDIT: Indeed, after rebuilding the sdk all files seem to be there, and compilation worked flawlessly!