2016-12-02 67 views
-1

我是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的正確方法?

+1

可能重複[如何在Linux上使用GCC編譯C和Gtk +](http://stackoverflow.com/questions/14944866/how-to-compile-c-and-gtk-with-gcc- on-linux) – Scribblemacher

+0

@Scribblemacher這些方法都不行。 –

+0

@ГригорийШепелев然後它可能太局部化了。 –

回答

0

我只是想出了什麼問題。 我有linuxbrew安裝,由於某種原因,pkg-config從它的一個倉庫中取走了路徑,即使我強制它導出。 我徹底刪除了linuxbrew,現在終於可以工作了! :)