编译 gtkmm 时出现问题
操作系统:Fedora 14
编译器:g++ (GCC) 4.5.1 20100924 (Red Hat 4.5.1-4)
我通过 yum 从存储库安装了 gtkmm24-devel。为了确保安装按计划进行,我决定尝试页面上的示例之一。
#include <gtkmm.h>
int main(int argc, char *argv[]) {
Gtk::Main kit(argc, argv);
Gtk::Window window;
Gtk::Main::run(window);
return 0;
}
我运行了这个例子,嘿!它说找不到 gtkmm.h,没问题,我只是忘了链接库。我通过 Eclipse 将 /usr/include/gtkmm-2.4 添加到我的库搜索中。不行,g++还是找不到!
fatal error: gtkmm.h: No such file or directory
然后我尝试使用 #include
包含 gtkmm 并重新编译,另一个错误! :(
/usr/include/gtkmm-2.4/gtkmm.h:87:20: fatal error: glibmm.h: No such file or directory
感谢您的阅读。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简短回答
使用“pkg-config gtkmm-2.4 --cflags”的输出作为包含路径,使用“pkg-config gtkmm-2.4 --libs”的输出作为要链接的库。
长答案
构建 C/C++ 程序分两个单独的步骤完成。首先编译源文件,输出目标文件;然后目标文件链接在一起。您收到的错误来自编译步骤。
在 Linux 上,大多数库都附带 pkgconfig 文件,以便其他程序更轻松地使用这些库。 gtkmm 还带有它自己的 pkgconfig 文件。
您正在尝试手动指定 /usr/include/gtkmm-2.4 作为包含路径;这是错误的。相反,使用 pkgconfig 的输出来确定头文件的位置。要获取 gtkmm 所需的所有包含目录,请使用以下命令:
对于链接,请使用以下 pkgconfig 命令获取需要链接的库:
您可以通过直接调用 g++ 在命令行上对其进行测试。
有关详细信息,请参阅 gtkmm 文档:http://library .gnome.org/devel/gtkmm-tutorial/unstable/sec-basics-simple-example.html.en
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
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:
For linking, use the following pkgconfig command to get the libraries you need to link with:
You can test it on the command line by invoking g++ directly.
For more information, see the gtkmm docs: http://library.gnome.org/devel/gtkmm-tutorial/unstable/sec-basics-simple-example.html.en
这些步骤通常有助于解决此问题:
正如评论中指出的,问题是编译器错误,并且编译器正在争论缺少(头)文件。我上面描述的步骤要么找到丢失文件的位置,要么帮助您安装头文件所属的库。
These steps usually help resolving this problem:
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.