torsdag 26 mars 2009

HOWTO use GTK+ with Eclipse

I found very little information on Google on how to use GTK+ 2.0 together with Eclipse and C/C++, which I recently had to do. This very small howto explains the procedure on Ubuntu.

First, if you dont have Eclipse installed, get the Eclipse tars for C/C++ development from eclipse.org. Install it and add

export PATH=$PATH:/usr/local/eclipse

to your .bashrc if you want.

Then get the libgtk and the gnome development kit:

sudo apt-get install libgtk2.0-dev
sudo apt-get install gnome-core-devel

If you are using C++ you want to get gtkmm (the C++ API for GTK+, not needed but strongly recommended):

sudo apt-get install libgtkmm-2.4-dev

Now fire up Eclipse. Create a new Managed Make C or C++ project.

GTK+ uses a lot of different include paths and libs. To facilitate development they have a nifty tool called pkg-config that generates the correct dependencies. Open up Project Properties -> C/C++ Build. Select the Tool Settings tab and then GCC C/C++ Compiler -> Miscellaneous. Append the following line to the end of "Other flags":

`pkg-config --cflags gtk+-2.0`

, if you are using the standard C API. If use are using gtkmm, instead put

`pkg-config --cflags gtkmm-2.4`

Add one of the following lines (depending if you use gtkmm or not) to GCC C/C++ Linker -> Miscellaneous -> Linker flags:

`pkg-config --libs gtk+-2.0`

or

`pkg-config --libs gtkmm-2.4`

Finished! Eclipse will now set up include paths and libraries correctly, although you will never see them in the project browser.

1 kommentar:

  1. Nice! Vad är skillnaden mellan GTK+ och GTKmm?

    SvaraRadera