Linux 找不到 glib.h 和 gtk.h

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5277284/
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-05 03:13:02  来源:igfitidea点击:

glib.h and gtk.h not found

clinuxgtkglibgtk2

提问by tariq

hi every one i have a program in which i have include

大家好,我有一个程序,其中包括

  • gtk/gtk.h
  • glib.h
  • gtk/gtk.h
  • glib.h

i have used commands

我用过命令

sudo apt-get install libgtk2.0-dev glib 
sudo apt-get install glade

but still getting error that glib not found ans gtk/gtk.h not found. i am first time using this gtk . no idea how it works how to install it kindly help me thanks

但仍然出现错误,未找到 glib ans gtk/gtk.h not found。我是第一次使用这个 gtk。不知道它是如何工作的 如何安装它 请帮助我 谢谢

i am doing c programming

我在做c编程

回答by Throwback1986

type "locate glib.h" to determine file's location (assuming a contemporary linux distribution - your post doesn't provide much information).

输入“locate glib.h”来确定文件的位置(假设是当代的 linux 发行版——你的帖子没有提供太多信息)。

Then ensure the path to glib.h is properly specified in your Makefile. (You do have a Makefile, don't you?) Perform the same steps for gtk.h.

然后确保在 Makefile 中正确指定了 glib.h 的路径。(您确实有一个 Makefile,不是吗?)对 gtk.h 执行相同的步骤。

回答by Petesh

The command you're supposed to use (in more recent releases of linux/gtk) is pkg-config, not gtk-config. gtk-config is intended for pre 2.0 gtk development.

您应该使用的命令(在 linux/gtk 的最新版本中)是 pkg-config,而不是 gtk-config。gtk-config 用于 2.0 之前的 gtk 开发。

Consider the file you're compiling is called foo.c, to compile it under gtk-2.0, you would use, from the command line the command:

考虑您正在编译的文件名为 foo.c,要在 gtk-2.0 下编译它,您将在命令行中使用以下命令:

gcc `pkg-config --cflags glib-2.0 gtk+-2.0` foo.c -o foo `pkg-config --libs glib-2.0 gtk+-2.0`

This should compile, and give you a file foo, that can be executed.

这应该会编译,并为您提供一个可以执行的文件 foo。

but really, use a makefile, as this stuff is a pain to keep typing. I would write out a sample makefile, but there are rules that need to be followed in the formatting of them that makes it difficult to type in the editor window.

但实际上,使用makefile,因为这些东西很难继续打字。我会写出一个示例makefile,但是在格式化它们时需要遵循一些规则,这使得在编辑器窗口中输入变得困难。

# Sample Makefile
CFLAGS := $(shell pkg-config --cflags glib-2.0 gtk+-2.0)
LDFLAGS := $(shell pkg-config --libs glib-2.0 gtk+-2.0)

foo: foo.c
<TAB HERE NOT SPACES>$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)

This defines a simple rule saying to make foo, it depends on foo.c, so of foo.c is newer than foo, it will be rebuilt. Where I write 'TAB HERE NOT SPACES' it mustbe a tab character, and cannot be a set of space characters.

这定义了一个简单的规则,说make foo,它依赖于foo.c,所以foo.c 比foo 新,它将被重建。在我写“TAB HERE NOT SPACES”的地方,它必须是制表符,不能是一组空格字符。

回答by liberforce

Please read the official documentation. It explains how to compile GTK applications. Basically to compile a hello.cfile to generate a helloprogram, you'll type:

请阅读官方文档。它解释了如何编译 GTK 应用程序。基本上要编译一个hello.c文件来生成一个hello程序,你需要输入:

gcc `pkg-config --cflags --libs gtk+-2.0` hello.c -o hello