Problems compiling gtkmm

橙三吉。 提交于 2019-12-20 10:32:39

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/4609705/problems-compiling-gtkmm

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!