无法构建示例 gtk+ 程序
Unable to build a example gtk+ program
我正在尝试构建一些 gtk+ 源代码附带的示例 gtk+ 示例。我只需要有一个 C 程序的 gtk+ UI 。我着手下载和构建 gtk+,但意识到(通过 SO)这不是必需的,我只需要 libgtk-3-dev。
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+ 附带的 makefile。
我尝试用我下载的 gtk+ 代码编译一个示例。我收到以下错误。关于这个主题的其他查询提到标志的顺序很重要,但在这种情况下,我使用了源代码附带的 makefile。我是否应该安装 libgtk-3-dev 库以外的东西(运行 on Ubuntu 14.04)。
~/gtk/examples/application1$ make -f Makefile.example
cc -c -o main.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 main.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/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/libpng12exampleapp.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/libpng12exampleappwin.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:(.text+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_peek_parent'
exampleapp.c:(.text+0x36): 未定义引用 g_type_class_adjust_private_offset'
exampleapp.o: In function
example_app_get_type':
exampleapp.c:(.text+0x66): 未定义引用 g_once_init_enter'
exampleapp.c:(.text+0x84): undefined reference to
g_intern_static_string'
exampleapp.c:(.text+0x8c): 未定义引用 gtk_application_get_type'
exampleapp.c:(.text+0xb4): undefined reference to
g_type_register_static_simple'
exampleapp.c:(.text+0xc9): 未定义引用 g_once_init_leave'
exampleapp.o: In function
example_app_activate':
exampleapp.c:(.text+0x104): 未定义引用 g_type_check_instance_cast'
exampleapp.c:(.text+0x115): undefined reference to
gtk_window_get_type'
exampleapp.c:(.text+0x127): 对 g_type_check_instance_cast'
exampleapp.c:(.text+0x12f): undefined reference to
gtk_window_present 的未定义引用
exampleapp.o: 在函数中 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:(.text+0x18c): 未定义引用 g_type_check_instance_cast'
exampleapp.c:(.text+0x1a9): undefined reference to
g_type_check_instance_cast'
exampleapp.c:(.text+0x1f5): 对 gtk_window_get_type'
exampleapp.c:(.text+0x207): undefined reference to
g_type_check_instance_cast 的未定义引用
exampleapp.c:(.text+0x20f): 对 gtk_window_present'
exampleapp.o: In function
example_app_class_init' 的未定义引用:
exampleapp.c:(.text+0x222): 对 g_application_get_type'
exampleapp.c:(.text+0x234): undefined reference to
g_type_check_class_cast 的未定义引用
exampleapp.c:(.text+0x244): 对 g_application_get_type'
exampleapp.c:(.text+0x256): undefined reference to
g_type_check_class_cast 的未定义引用
exampleapp.o: 在函数中 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:(.text+0x36): 未定义引用 g_type_class_adjust_private_offset'
exampleappwin.o: In function
example_app_window_get_type':
exampleappwin.c:(.text+0x66): 未定义引用 g_once_init_enter'
exampleappwin.c:(.text+0x84): undefined reference to
g_intern_static_string'
exampleappwin.c:(.text+0x8c): 对 gtk_application_window_get_type'
exampleappwin.c:(.text+0xb4): undefined reference to
g_type_register_static_simple' 的未定义引用
exampleappwin.c:(.text+0xc9): 对 g_once_init_leave'
exampleappwin.o: In function
example_app_window_new' 的未定义引用:
exampleappwin.c:(.text+0x117): 对“g_object_new”的未定义引用
collect2:错误:ld 返回 1 退出状态
make: *** [exampleapp] 错误 1
无论出于何种原因,GTK+ 3.20 源代码树中的 Makefile 已损坏;根据 n.m. 的评论。可能已经有错误修复,如果不是修复的话。
但是您不能将 GTK+ 3.20 与 Ubuntu 14.04 LTS 附带的 GTK+ 3.10 一起使用。您最好使用 GTK+ 3.10 示例和源代码。如果你真的想使用较新版本的 GTK+,你可以使用 jhbuild 设置一个与系统其余部分分开的环境(通常在 /opt/gnome
中)以将较新版本的 GTK+ 构建到其中。
我正在尝试构建一些 gtk+ 源代码附带的示例 gtk+ 示例。我只需要有一个 C 程序的 gtk+ UI 。我着手下载和构建 gtk+,但意识到(通过 SO)这不是必需的,我只需要 libgtk-3-dev。
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+ 附带的 makefile。
我尝试用我下载的 gtk+ 代码编译一个示例。我收到以下错误。关于这个主题的其他查询提到标志的顺序很重要,但在这种情况下,我使用了源代码附带的 makefile。我是否应该安装 libgtk-3-dev 库以外的东西(运行 on Ubuntu 14.04)。
~/gtk/examples/application1$ make -f Makefile.example
cc -c -o main.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 main.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/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/libpng12exampleapp.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/libpng12exampleappwin.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:(.text+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_peek_parent'
exampleapp.c:(.text+0x36): 未定义引用 g_type_class_adjust_private_offset'
exampleapp.o: In function
example_app_get_type':
exampleapp.c:(.text+0x66): 未定义引用 g_once_init_enter'
exampleapp.c:(.text+0x84): undefined reference to
g_intern_static_string'
exampleapp.c:(.text+0x8c): 未定义引用 gtk_application_get_type'
exampleapp.c:(.text+0xb4): undefined reference to
g_type_register_static_simple'
exampleapp.c:(.text+0xc9): 未定义引用 g_once_init_leave'
exampleapp.o: In function
example_app_activate':
exampleapp.c:(.text+0x104): 未定义引用 g_type_check_instance_cast'
exampleapp.c:(.text+0x115): undefined reference to
gtk_window_get_type'
exampleapp.c:(.text+0x127): 对 g_type_check_instance_cast'
exampleapp.c:(.text+0x12f): undefined reference to
gtk_window_present 的未定义引用
exampleapp.o: 在函数中 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:(.text+0x18c): 未定义引用 g_type_check_instance_cast'
exampleapp.c:(.text+0x1a9): undefined reference to
g_type_check_instance_cast'
exampleapp.c:(.text+0x1f5): 对 gtk_window_get_type'
exampleapp.c:(.text+0x207): undefined reference to
g_type_check_instance_cast 的未定义引用
exampleapp.c:(.text+0x20f): 对 gtk_window_present'
exampleapp.o: In function
example_app_class_init' 的未定义引用:
exampleapp.c:(.text+0x222): 对 g_application_get_type'
exampleapp.c:(.text+0x234): undefined reference to
g_type_check_class_cast 的未定义引用
exampleapp.c:(.text+0x244): 对 g_application_get_type'
exampleapp.c:(.text+0x256): undefined reference to
g_type_check_class_cast 的未定义引用
exampleapp.o: 在函数中 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:(.text+0x36): 未定义引用 g_type_class_adjust_private_offset'
exampleappwin.o: In function
example_app_window_get_type':
exampleappwin.c:(.text+0x66): 未定义引用 g_once_init_enter'
exampleappwin.c:(.text+0x84): undefined reference to
g_intern_static_string'
exampleappwin.c:(.text+0x8c): 对 gtk_application_window_get_type'
exampleappwin.c:(.text+0xb4): undefined reference to
g_type_register_static_simple' 的未定义引用
exampleappwin.c:(.text+0xc9): 对 g_once_init_leave'
exampleappwin.o: In function
example_app_window_new' 的未定义引用:
exampleappwin.c:(.text+0x117): 对“g_object_new”的未定义引用
collect2:错误:ld 返回 1 退出状态
make: *** [exampleapp] 错误 1
无论出于何种原因,GTK+ 3.20 源代码树中的 Makefile 已损坏;根据 n.m. 的评论。可能已经有错误修复,如果不是修复的话。
但是您不能将 GTK+ 3.20 与 Ubuntu 14.04 LTS 附带的 GTK+ 3.10 一起使用。您最好使用 GTK+ 3.10 示例和源代码。如果你真的想使用较新版本的 GTK+,你可以使用 jhbuild 设置一个与系统其余部分分开的环境(通常在 /opt/gnome
中)以将较新版本的 GTK+ 构建到其中。