Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems compiling gtkmm

Tags:

c++

eclipse

gtkmm

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.

like image 970
t3hb4tman Avatar asked Jan 05 '11 22:01

t3hb4tman


2 Answers

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

like image 100
kalev Avatar answered Sep 19 '22 12:09

kalev


These steps usually help resolving this problem:

  • Search your computer for glibmm.h
    • If found - add its directory to the include path list
    • If not found - Google for glibmm.h and find out which library it is contained in. You will find out in this case it's (surprise!) glibmm. Install it using your package manager.

The problem, as noted in comments, is a compiler error and the compiler is arguing about a missing (header) file. The steps I described above either find the location of the missing file or help you to install a library that the header file belongs to.

like image 25
Karel Petranek Avatar answered Sep 19 '22 12:09

Karel Petranek