Problems compiling gtkmm

t3hb4tman picture t3hb4tman · Jan 5, 2011 · Viewed 25.1k times · Source

OS: Fedora 14

Compiler: g++ (GCC) 4.5.1 20100924 (Red Hat 4.5.1-4)

I installed gtkmm24-devel from repository via yum. To make sure the install went as planned I decided to try one of the examples on the page.

#include <gtkmm.h>

int main(int argc, char *argv[]) {
    Gtk::Main kit(argc, argv);
    Gtk::Window window;
    Gtk::Main::run(window);
    return 0;
}

I ran the example, and, hey! It said it couldn't find gtkmm.h, no problem, I just forgot to link the library. I added /usr/include/gtkmm-2.4 to my library search through Eclipse. No bueno, g++ still can't find it!

fatal error: gtkmm.h: No such file or directory

I then try to include gtkmm by using #include <gtkmm-2.4/gtkmm.h> and recompile, another error! :(

/usr/include/gtkmm-2.4/gtkmm.h:87:20: fatal error: glibmm.h: No such file or directory

Thanks for reading.

Answer

kalev picture kalev · Jan 6, 2011

Short answer

Use the output of 'pkg-config gtkmm-2.4 --cflags' for include paths and 'pkg-config gtkmm-2.4 --libs' for libraries to link.

Long answer

It said it couldn't find gtkmm.h, no problem, I just forgot to link the library.

Building a C/C++ program is done in two separate steps. First the source files are compiled, outputting object files; and then the object files are linked together. The error you are getting comes from the compiling step.

On Linux, most libraries come with pkgconfig files to make it easier for other programs to use the libraries. gtkmm also comes with its own pkgconfig files.

You are trying to manually specify /usr/include/gtkmm-2.4 for include path; this is wrong. Instead, use the output of pkgconfig to figure out where the header files are located. To get all the include directories needed for gtkmm, use the following command:

pkg-config gtkmm-2.4 --cflags

For linking, use the following pkgconfig command to get the libraries you need to link with:

pkg-config gtkmm-2.4 --libs

You can test it on the command line by invoking g++ directly.

g++ myfirstprogram.cpp -o myfirstprogram `pkg-config gtkmm-2.4 --cflags --libs`

For more information, see the gtkmm docs: http://library.gnome.org/devel/gtkmm-tutorial/unstable/sec-basics-simple-example.html.en