2016-05-14 80 views
1

我正在嘗試構建一些gtk +源代碼隨附的示例gtk +示例。我的需要只是爲C程序提供gtk + UI。我開始下載和構建gtk +,但是意識到(通過SO),這是不需要的,我只需要libgtk-3-dev。無法構建示例gtk +程序

sudo apt-get install libgtk-3-dev 
Reading package lists... Done 
Building dependency tree  
Reading state information... Done 
libgtk-3-dev is already the newest version. 
0 upgraded, 0 newly installed, 0 to remove and 373 not upgraded. 

編輯:注意:問題不是與庫的序列或包括,因爲我正在使用gtk +隨附的生成文件。

我試着編譯一個我用下載的gtk +代碼的例子。我得到下面的錯誤。關於這個主題的其他查詢提到了標誌的順序,但在這種情況下,我使用了隨源提供的makefile。我應該安裝比libgtk-3-dev庫(在Ubuntu 14.04上運行)更多的東西。

~/gtk/examples/application1$ make -f Makefile.example 

立方厘米-c -o main.o -pthread -I的/ usr /包括/ GTK-3.0 -I的/ usr /包括/ ATK-1.0 -I的/ usr /包括/ 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 m​​ain.c cc -c -o exampleapp.o -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/freetype2 -I/usr/include/freetype2 usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/harfbuzz- 1 -I/usr/include/li bpng12 exampleapp.c cc -c -o exampleappwin.o -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 exampleappwin.c cc -o exampleapp -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 main.o exampleapp.o exampleappwin.o main.o:在功能main': main.c:(.text+0x11): undefined reference to g_application_get_type ' main.c中:(文本+ 0X24):未定義參照g_type_check_instance_cast' main.c:(.text+0x35): undefined reference to g_application_run' exampleapp.o:在功能example_app_class_intern_init': exampleapp.c:(.text+0x14): undefined reference to g_type_class_pee k_parent」 exampleapp.c :(文本+ 0x36):未定義參照g_type_class_adjust_private_offset' exampleapp.o: In function example_app_get_type ': exampleapp.c :(文本+ 0x66):未定義參照g_once_init_enter' exampleapp.c:(.text+0x84): undefined reference to g_intern_static_string' exampleapp.c :(文本+ 0x8c) :未定義參照gtk_application_get_type' exampleapp.c:(.text+0xb4): undefined reference to g_type_register_static_simple」 exampleapp.c :(文本+ 0xc9):未定義參照g_once_init_leave' exampleapp.o: In function example_app_activate ': exampleapp.c :(文本+量0x104):未定義參照g_type_check_instance_cast' exampleapp.c:(.text+0x115): undefined reference to gtk_window_get_type' exampleapp.c :(.text + 0x127):undefined reference to g_type_check_instance_cast' exampleapp.c:(.text+0x12f): undefined reference to gtk_window_present' exampleapp.o:In function example_app_open': exampleapp.c:(.text+0x14d): undefined reference to gtk_application_get_type' exampleapp.c :(。text + 0x15f):未定義參照g_type_check_instance_cast' exampleapp.c:(.text+0x167): undefined reference to gtk_application_get_windows' exampleapp.c :(文本+ 0x18c):未定義參照g_type_check_instance_cast' exampleapp.c:(.text+0x1a9): undefined reference to g_type_check_instance_cast ' exampleapp.c :(文本+ 0x1f5):未定義參照gtk_window_get_type' exampleapp.c:(.text+0x207): undefined reference to g_type_check_instance_cast' exampleapp.c :(文本。 + 0x20f):未定義參照gtk_window_present' exampleapp.o: In function example_app_class_init ': exampleapp.c :(文本+ 0x222):未定義參照g_application_get_type' exampleapp.c:(.text+0x234): undefined reference to g_type_check_class_cast' exampleapp.c :(文本+ 0x244):未定義參照g_application_get_type' exampleapp.c:(.text+0x256): undefined reference to g_type_check_class_cast」 ExampleApp中。○:在功能example_app_new': exampleapp.c:(.text+0x294): undefined reference to g_object_new ' exampleappwin.o:在功能example_app_window_class_intern_init': exampleappwin.c:(.text+0x14): undefined reference to g_type_class_peek_parent'。 exampleappwin.c :(文本+ 0x36):未定義參照g_type_class_adjust_private_offset' exampleappwin.o: In function example_app_window_get_type': exampleappwin.c :(文本+ 0x66):未定義參考到g_once_init_enter' exampleappwin.c:(.text+0x84): undefined reference to g_intern_static_string ' exampleappwin.c :(文本+ 0x8c):未定義參照gtk_application_window_get_type' exampleappwin.c:(.text+0xb4): undefined reference to g_type_register_static_simple'。 exampleappwin.c :(文本+ 0xc9):未定義參照g_once_init_leave' exampleappwin.o: In function example_app_window_new': exampleappwin.c :(文本+ 0x117):未定義引用'g_object_new' collect2:錯誤:ld返回1退出狀態 make:*** [exampleapp]錯誤1

+1

Ubuntu 14.04只附帶GTK + 3.10;您將無法使用它爲新版GTK +構建示例。獲取GTK + 3.10源代碼的一個版本,並且應該構建這些示例。 – andlabs

+0

[爲什麼庫鏈接的順序有時會導致GCC錯誤?](http://stackoverflow.com/questions/45135/why-does-the-order-in-which-libraries-are- linked-sometimes-cause-errors-in-gcc)TL; DR將'main.o'移到所有'-lxxx'前面。 –

+0

@ n.m。他們正在嘗試構建一個GTK +源代碼的例子,而不是他們自己的程序。這些示例已經有了正確的makefile。如果這實際上是這裏的問題,那麼這些makefile就會被破壞...... – andlabs

回答

1

無論出於何種原因,GTK + 3.20源代碼樹中的Makefile被破壞;根據n.m.的評論。這可能已經有了一個錯誤修正,如果不是修復的話。

但是,您不能在Ubuntu 14.04 LTS附帶的GTK + 3.10中使用GTK + 3.20。你最好使用GTK + 3.10的例子和源代碼。如果你真的想使用更新版本的GTK +,你可以使用jhbuild來建立一個獨立於系統其他部分的環境(通常在/opt/gnome)來構建更新版本的GTK +。

+0

根據你以前的評論,我沒有下載gtk + 3.10.9,配置成功。構建的例子但它搞亂了我的桌面環境,並開始得到一個低圖形錯誤。必須通過make卸載進行卸載。 – user132797