C++ 编译gtkmm的问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4609705/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 15:54:59  来源:igfitidea点击:

Problems compiling gtkmm

c++eclipsegtkmm

提问by t3hb4tman

OS: Fedora 14

操作系统:Fedora 14

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

编译器: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.

我通过 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;
}

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!

我运行了这个例子,嘿!它说找不到gtkmm.h,没问题,我只是忘记链接库了。我通过 Eclipse 将 /usr/include/gtkmm-2.4 添加到我的库搜索中。没有 bueno,g++ 仍然找不到它!

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! :(

然后我尝试通过使用#include <gtkmm-2.4/gtkmm.h>和重新编译来包含 gtkmm ,另一个错误!:(

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

Thanks for reading.

谢谢阅读。

回答by kalev

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.

将“pkg-config gtkmm-2.4 --cflags”的输出用于包含路径,将“pkg-config gtkmm-2.4 --libs”的输出用于要链接的库。

Long answer

长答案

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

它说找不到gtkmm.h,没问题,我只是忘记链接库了。

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.

构建 C/C++ 程序分两个单独的步骤完成。首先编译源文件,输出目标文件;然后将目标文件链接在一起。您得到的错误来自编译步骤。

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.

在 Linux 上,大多数库都带有 pkg​​config 文件,以使其他程序更容易使用这些库。gtkmm 也带有它自己的 pkgconfig 文件。

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:

您正在尝试为包含路径手动指定 /usr/include/gtkmm-2.4;这是错误的。相反,使用 pkgconfig 的输出来确定头文件所在的位置。要获取 gtkmm 所需的所有包含目录,请使用以下命令:

pkg-config gtkmm-2.4 --cflags

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

对于链接,使用以下 pkgconfig 命令来获取您需要链接的库:

pkg-config gtkmm-2.4 --libs

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

您可以通过直接调用 g++ 在命令行上对其进行测试。

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

有关更多信息,请参阅 gtkmm 文档:http: //library.gnome.org/devel/gtkmm-tutorial/unstable/sec-basics-simple-example.html.en

回答by Karel Petranek

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.hand 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.
  • 在您的计算机上搜索 glibmm.h
    • 如果找到 - 将其目录添加到包含路径列表中
    • 如果没有找到 -谷歌搜索 glibmm.h并找出它包含在哪个库中。你会发现在这种情况下它是(惊喜!)glibmm。使用您的包管理器安装它。

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.

正如评论中所指出的,问题是编译器错误,并且编译器正在争论缺少(头)文件。我上面描述的步骤要么找到丢失文件的位置,要么帮助您安装头文件所属的库。