gtkmm:简单示例无法编译:gtkmm.h:没有此类文件或目录 [英] gtkmm: Simple example fails to compile: gtkmm.h: No such file or directory

查看:697
本文介绍了gtkmm:简单示例无法编译:gtkmm.h:没有此类文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读gtkmm文档。我首先尝试编译简单示例。这是代码。也可以在此处找到

I am working through the gtkmm documentation. I have started by trying to compile the "Simple Example". Here is the code. It can also be found here.

/// SimpleExample.cpp

#include <gtkmm.h>

int main(int argc, char *argv[])
{
  auto app =
    Gtk::Application::create(argc, argv,
      "org.gtkmm.examples.base");

  Gtk::Window window;
  window.set_default_size(200, 200);

  return app->run(window);
}

我尝试使用

g++ SimpleExample.cpp -o SimpleExample `pkg-config gtkmm-3.0 --cflags --libs`

应该根据文档工作。 (请参见链接页面的末尾。)

which should work according to the documentation. (See end of linked page.)

运行 pkg-config gtkmm-3.0 --cflags --libs 会产生

Package gtkmm-3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtkmm-3.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtkmm-3.0' found

我正在运行Debian 9 Stretch。我安装了 gtkmm

I am running Debian 9 Stretch. I installed gtkmm with

sudo apt update && sudo apt install libgtkmm-3.0-dev

运行 find / usr -name gtkmm 产生

/usr/lib/x86_64-linux-gnu/pkgconfig/gtkmm-3.0.pc
/usr/lib/x86_64-linux-gnu/gtkmm-3.0
/usr/lib/x86_64-linux-gnu/gtkmm-3.0/include/gtkmmconfig.h
/usr/include/gtkmm-3.0
/usr/include/gtkmm-3.0/gtkmm
/usr/include/gtkmm-3.0/gtkmm.h

那么为什么示例无法编译?

So why does the example not compile?

新终端

pkg-config gtkmm-3.0 --cflags --libs
Package gtkmm-3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtkmm-3.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtkmm-3.0' found

尝试

find /usr -name "*gtkmm-3.0*"
/usr/lib/x86_64-linux-gnu/pkgconfig/gtkmm-3.0.pc
/usr/lib/x86_64-linux-gnu/libgtkmm-3.0.so.1.1.0
/usr/lib/x86_64-linux-gnu/libgtkmm-3.0.so.1
/usr/lib/x86_64-linux-gnu/gtkmm-3.0
/usr/lib/x86_64-linux-gnu/libgtkmm-3.0.so
/usr/share/doc/libgtkmm-3.0-1v5
/usr/share/doc/libgtkmm-3.0-dev
/usr/include/gtkmm-3.0

导出位置

export PKG_CONFIG_PATH="/usr/lib/x86_64-linux-gnu/pkgconfig"

重新运行

pkg-config gtkmm-3.0 --cflags --libs
Package xproto was not found in the pkg-config search path.
Perhaps you should add the directory containing `xproto.pc'
to the PKG_CONFIG_PATH environment variable
Package 'xproto', required by 'xau', not found

(这次是不同的错误。)

(That's a different error this time.)

尝试再次查找

find /usr -name "*xproto*"
/usr/share/pkgconfig/xproto.pc
/usr/include/xcb/xproto.h
/usr/include/GL/glxproto.h
/usr/include/X11/extensions/lbxproto.h

更改导出命令

export PKG_CONFIG_PATH="/usr/lib/x86_64-linux-gnu/pkgconfig;/usr/share/pkgconfig"

重新运行,回到第1格

pkg-config gtkmm-3.0 --cflags --libs
Package gtkmm-3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtkmm-3.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtkmm-3.0' found



问题已解决(排序)



我通过阅读问题,该路径应以冒号分隔。

Problem resolved (sort ot)

I have discovered from reading this question that the path should be colon seperated.

    export PKG_CONFIG_PATH="/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/share/pkgconfig"

但是,这并不能解决为什么需要完全设置此变量的问题。使用 pkg-config 是因为它可以简化编译,但是,这比手动指定include路径更简单,因为需要设置多个环境变量。

However this does not solve the problem of why this variable needs to be set at all. pkg-config is used because it is supposed to make compilation simpler, however this isn't any more simple than specifying the include paths manually, as multiple environment variables need to be set.

此外,由于缺少有关此问题的在线信息,我怀疑这是大多数用户没有遇到的问题,因此可能是Debian 9特有的。 (我想知道是否有人遇到过这个问题,以及在什么操作系统上。)

In addition, the lack of information about this issue online makes me suspect that this is an issue which most users do not encounter, and therefore is probably specific to Debian 9. (I would like to know if anyone else has encounted this problem, and on what OS.)

推荐答案

首先,它通常安装gtkmm有点复杂。据我所知,在这里的Stackoverflow论坛中,许多用户对此有问题。如果他们试图将gtkmm和Visual Studio一起用于开发独立于平台的应用程序,那么即使Windows操作系统中的用户也会遇到错误消息。但是,这是您的问题。有很多选择可能会出错。一个简单的解释是,必须安装debian软件包 libgtk-3-dev,该软件包用于在C语言中创建GTK +应用程序,因为gtkmm使用了该软件包。所以第一步就是尝试一下,它可以为GTK +编译C源代码。第二种解释是,debian的软件包管理器通常已损坏,因此切换Linux发行版将是一个不错的建议。例如,在Fedora中,简单的 dnf安装gtk3 gtk3-devel gtkmm30 gtkmm30-devel 就可以开始编程。

At first, it is normal that installing gtkmm is a bit complicated. As far as i can see, here in the Stackoverflow forum many users have problem with doing so. Even users in the Windows operating system are confronted with error messages, if they are trying to use gtkmm together with Visual Studio for developing a platform independent app ... But to your question. There are many options what can go wrong. A simple explanation would be, that the debian package "libgtk-3-dev" has to be installed, which is used for creating GTK+ apps in C, because gtkmm uses this package. So the first step is to try out, it the compilation of a C sourcecode for GTK+ works. A second explanation is, that the debian "package manager" is in general broken so switching the Linux distribution would be a good advice. For example, in Fedora a simple dnf install gtk3 gtk3-devel gtkmm30 gtkmm30-devel is enough for starting programming.

这篇关于gtkmm:简单示例无法编译:gtkmm.h:没有此类文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆