如何使用GTK C库?
问题描述:
我是C新手,并开始学习如何创建GUI。 出于某种原因,只有这样,程序运行是如何使用GTK C库?
gcc simple.c -o simple -lgtk-3 -lgdk-3 -latk-1.0 -lgio-2.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo-gobject -lpango-1.0 -lcairo -lgobject-2.0 -lglib-2.0 -pthread -I/usr/include/gtk-3.0 -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/pixman-1 -I/usr/include/libpng12
,如果我只是运行gcc simple.c
它给了我
In file included from /usr/include/glib-2.0/glib/galloca.h:32:0,
from /usr/include/glib-2.0/glib.h:30,
from /usr/include/glib-2.0/gobject/gbinding.h:28,
from /usr/include/glib-2.0/glib-object.h:23,
from /usr/include/glib-2.0/gio/gioenums.h:28,
from /usr/include/glib-2.0/gio/giotypes.h:28,
from /usr/include/glib-2.0/gio/gio.h:26,
from /usr/include/gtk-2.0/gdk/gdkapplaunchcontext.h:30,
from /usr/include/gtk-2.0/gdk/gdk.h:32,
from /usr/include/gtk-2.0/gtk/gtk.h:32,
from graphical.c:1:/usr/include/glib-2.0/glib/gtypes.h:32:24: fatal error: glibconfig.h: No such file or catalog compilation terminated.
如果我做其他的“传统”的方式包括lib目录下:
gcc `pkg-config gtk+-2.0 --cflags` example.c -o example `pkg-config gtk+-2.0 --libs`
它给我:
Package gtk+-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtk+-2.0.pc' to the PKG_CONFIG_PATH environment variable
No package 'gtk+-2.0' found
graphical.c:1:21: fatal error: gtk/gtk.h: No such file or catalog
什么是包含GTK的正确方法?
答
我只是想出了什么问题。 我有linuxbrew安装,由于某种原因,pkg-config从它的一个仓库中取走了路径,即使我强制它导出。 我彻底删除了linuxbrew,现在终于可以工作了! :)
可能重复[如何在Linux上使用GCC编译C和Gtk +](http://*.com/questions/14944866/how-to-compile-c-and-gtk-with-gcc- on-linux) – Scribblemacher
@Scribblemacher这些方法都不行。 –
@ГригорийШепелев然后它可能太局部化了。 –