How to setup GTK+ to develop with Code::Blocks on Ubuntu Linux

23,698

Assuming that you have located and installed the correct package. As of 2011, the current package was libgtk-3-dev then the pkg-config tool can be used to extract the linker and compiler flags - and with proper escaping in the Code:Blocks settings can inject the correct settings automatically.

Open Code::Blocks Settings > Compiler and Linker Settings... and add the following under Global Compiler Settings > Compiler Settings > Other Options

`pkg-config --cflags gtk+-3.0`

and add this to Global Compiler Settings > Linker Settings > Other Options

`pkg-config --libs gtk+-3.0`

With the ` this has the effect of running the pkg-config tool calling --cflags gtk+-3.0 (or --libs) which, assuming libgtk3-dev is installed, injects the necessary search folders and lib directives onto the gcc command line.


As an alternative, developer.ubuntu.com lists Anjuta as a C/C++ IDE that can create GTK+ projects. As an alternative to Code::Blocks its far more polished as an Ubuntu IDE.


Scratch that. Anjuta looses its sheen quickly.

Share:
23,698
Chris Becke
Author by

Chris Becke

Updated on July 05, 2022

Comments

  • Chris Becke
    Chris Becke almost 2 years

    I am trying to develop a GTK+ application on Ubuntu 11.4, using Code::Blocks.

    www.gtk.org has instructions on building GTK+ from source, that looked complicated. But the Ubuntu package manager listed libgtk3-dev as a package that I installed.

    Code::Blocks I installed using the Ubuntu Software Center.

    Using the Code::Blocks project wizard to create a GTK+ project, when I build, the project fails to compile "cannot find gtk/gtk.h".

    Clearly the GTK include (and lib) folders are not added to the Code::Blocks search folders. I have located the relevant paths and files...

    Do I have to explicitly & manually add all the search paths to Code::Blocks' search paths? Or am I missing some installation step.