LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1256|回复: 3

gtk for winodws 编译不成功。

[复制链接]
发表于 2010-4-22 21:55:40 | 显示全部楼层 |阅读模式
我是个编程自学者。用VB写过一点程序。 用VBA,为EXCEL和CAD的自动化办公,写了不少东西。
我会一点C,想用gtk 在 windows XP 下编程。
可是装了mingw 和 gtk , 编译不成功。

mingw 装的是当前 的stable版,gcc是3.4.5的。 设了path 路径。编译一个hello world, 成功了。
gtk+ 装的是gtk+-bundle_2.16.1-20090419_win32.zip 。装完了,也设了个path路径。

编译下面这段程序:
  1. #include <gtk/gtk.h>
  2. static gboolean delete_event( GtkWidget *widget, GdkEvent *event, gpointer data )
  3. {
  4.    g_print ("delete event occurred\n");
  5.    return FALSE;
  6. }
  7. static void destroy( GtkWidget *widget, gpointer data )
  8. {
  9.    gtk_main_quit ();
  10. }
  11. int main( int argc, char *argv[] )
  12. {
  13.    GtkWidget *window;
  14.    GtkWidget *label;
  15.    gtk_init (&argc, &argv);
  16.    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  17.    g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (delete_event), NULL);
  18.    g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (destroy), NULL);
  19.    label = gtk_label_new ("Hello GTK");
  20.    gtk_container_add (GTK_CONTAINER (window), label);
  21.    gtk_container_set_border_width (GTK_CONTAINER (window), 10);
  22.    gtk_widget_show (label);
  23.    gtk_widget_show (window);
  24.    gtk_main ();
  25.    return 0;
  26. }
复制代码

编译命令和出错信息如下:
  1. E:\temp>mingw32-gcc -g -mms-bitfields -Ie:/mingw/include -Ie:/gtk/include/gtk-2.0 -Ie:/gtk/lib/gtk-2.0/include -Ie:/gtk
  2. include/atk-1.0 -Ie:/gtk/include/cairo -Ie:/gtk/include/pango-1.0 -Ie:/gtk/include/glib-2.0 -Ie:/gtk/lib/glib-2.0/inclu
  3. e -Ie:/gtk/include/libpng12  -Le:/mingw/lib -Le:/gtk/lib -lgtk-win32-2.0 -lgdk-win32-2.0 -latk-1.0 -lgio-2.0 -lgdk_pixb
  4. f-2.0 -lpangowin32-1.0 -lgdi32 -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lintl  test
  5. c
  6. C:\DOCUME~1\Lixw\LOCALS~1\Temp/cchUZViZ.o: In function `expose_event_callback':
  7. E:/temp/test.c:19: undefined reference to `gtk_widget_get_style'
  8. E:/temp/test.c:21: undefined reference to `gdk_draw_rectangle'
  9. C:\DOCUME~1\Lixw\LOCALS~1\Temp/cchUZViZ.o: In function `change_color_callback':
  10. E:/temp/test.c:39: undefined reference to `gtk_color_selection_dialog_new'
  11. E:/temp/test.c:41: undefined reference to `gtk_window_get_type'
  12. E:/temp/test.c:41: undefined reference to `g_type_check_instance_cast'
  13. E:/temp/test.c:41: undefined reference to `gtk_window_get_type'
  14. E:/temp/test.c:41: undefined reference to `g_type_check_instance_cast'
  15. E:/temp/test.c:41: undefined reference to `gtk_window_set_transient_for'
  16. E:/temp/test.c:43: undefined reference to `gtk_color_selection_get_type'
  17. E:/temp/test.c:43: undefined reference to `gtk_color_selection_dialog_get_type'
  18. E:/temp/test.c:43: undefined reference to `g_type_check_instance_cast'
  19. E:/temp/test.c:43: undefined reference to `g_type_check_instance_cast'
  20. E:/temp/test.c:45: undefined reference to `gtk_color_selection_set_previous_color'
  21. E:/temp/test.c:46: undefined reference to `gtk_color_selection_set_current_color'
  22. E:/temp/test.c:47: undefined reference to `gtk_color_selection_set_has_palette'
  23. E:/temp/test.c:49: undefined reference to `gtk_dialog_get_type'
  24. E:/temp/test.c:49: undefined reference to `g_type_check_instance_cast'
  25. E:/temp/test.c:49: undefined reference to `gtk_dialog_run'
  26. E:/temp/test.c:53: undefined reference to `gtk_color_selection_get_current_color'
  27. E:/temp/test.c:56: undefined reference to `gtk_widget_modify_bg'
  28. E:/temp/test.c:59: undefined reference to `gtk_widget_destroy'
  29. C:\DOCUME~1\Lixw\LOCALS~1\Temp/cchUZViZ.o: In function `do_colorsel':
  30. E:/temp/test.c:75: undefined reference to `gtk_window_new'
  31. E:/temp/test.c:76: undefined reference to `gtk_widget_get_screen'
  32. E:/temp/test.c:76: undefined reference to `gtk_window_get_type'
  33. E:/temp/test.c:76: undefined reference to `g_type_check_instance_cast'
  34. E:/temp/test.c:76: undefined reference to `gtk_window_set_screen'
  35. E:/temp/test.c:78: undefined reference to `gtk_window_get_type'
  36. E:/temp/test.c:78: undefined reference to `g_type_check_instance_cast'
  37. E:/temp/test.c:78: undefined reference to `gtk_window_set_title'
  38. E:/temp/test.c:80: undefined reference to `gtk_widget_destroyed'
  39. E:/temp/test.c:80: undefined reference to `g_signal_connect_data'
  40. E:/temp/test.c:83: undefined reference to `gtk_container_get_type'
  41. E:/temp/test.c:83: undefined reference to `g_type_check_instance_cast'
  42. E:/temp/test.c:83: undefined reference to `gtk_container_set_border_width'
  43. E:/temp/test.c:85: undefined reference to `gtk_vbox_new'
  44. E:/temp/test.c:86: undefined reference to `gtk_container_get_type'
  45. E:/temp/test.c:86: undefined reference to `g_type_check_instance_cast'
  46. E:/temp/test.c:86: undefined reference to `gtk_container_set_border_width'
复制代码
出错信息很多,只贴出来一段。基本上是所有的gtk函数都没有找到。

请高手帮忙解答,为什么找不到函数参考。
发表于 2010-4-23 09:08:56 | 显示全部楼层
楼主需要学习pkg-config的用法,记忆这些include和lib路径非人类所长。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2010-4-23 12:46:52 | 显示全部楼层
是路径的问题吗? 回去再查查,是不是复制粘贴的乱了。
回复 支持 反对

使用道具 举报

发表于 2010-9-13 09:04:23 | 显示全部楼层
你不能在 windows 下用

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

而要调整 -l 选项的位置到最后

CC = gcc
all:
        $(CC) -mms-bitfields -Id:/dev/gtk/include/gtk-2.0 -Id:/dev/gtk/lib/gtk-2.0/include -Id:/dev/gtk/include/atk-1.0 -Id:/dev/gtk/include/cairo -Id:/dev/gtk/include/pango-1.0 -Id:/dev/gtk/include/glib-2.0 -Id:/dev/gtk/lib/glib-2.0/include -Id:/dev/gtk/include/freetype2 -Id:/dev/gtk/include -Id:/dev/gtk/include/libpng14  -Ld:/dev/gtk/lib hello.c -o hello -lgtk-win32-2.0 -lgdk-win32-2.0 -latk-1.0 -lgio-2.0 -lgdk_pixbuf-2.0 -lpangowin32-1.0 -lgdi32 -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lglib-2.0 -lintl

以上是我的 makefile 你可以看到位置的变化。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表