Chinaunix

标题: Help!GTK编译问题! [打印本页]

作者: Joelay    时间: 2004-11-07 23:15
标题: Help!GTK编译问题!
gcc -L/gtkwin32/lib -lglib-2.0 -lgtk-win32-2.0 -o gtktest.exe gtktest.o
gtktest.o(.text+0x1c):gtktest.c: undefined reference to `g_print'
gtktest.o(.text+0x4b):gtktest.c: undefined reference to `g_print'
gtktest.o(.text+0x60):gtktest.c: undefined reference to `gtk_main_quit'
gtktest.o(.text+0xc2):gtktest.c: undefined reference to `gtk_init_abi_check'
gtktest.o(.text+0xcf):gtktest.c: undefined reference to `gtk_window_new'
........
作者: Joelay    时间: 2004-11-08 12:40
标题: Help!GTK编译问题!
自己定一下。难道就没有用过gtk的高手么……
作者: Joelay    时间: 2004-11-09 16:30
标题: Help!GTK编译问题!
不能干了!
E:\eclipse\workspace\GtkTest>;make -f makefile.icl
icl -I\gtkwin32\include -I\gtkwin32\include\glib-2.0 -I\gtkwin32\include\gtk-2.0 -I\gtkwin32\lib\glib-2.0\include -I\gtkwin32\lib\gtk-2.0\include -I\gtkwin32\include\atk-1.0 -I\gtkwin32\include\pango-1.0 -c gtktest.c
Intel(R) C++ Compiler for 32-bit applications, Version 8.1    Build 20040802Z Package ID: W_CC_P_8.1.018
Copyright (C) 1985-2004 Intel Corporation.  All rights reserved.
30 DAY EVALUATION LICENSE

icl: NOTE: The evaluation period for this product ends on 4-dec-2004 UTC.
gtktest.c
icl \gtkwin32\lib\glib-2.0.lib \gtkwin32\lib\gtk-win32-2.0.lib \gtkwin32\lib\gobject-2.0.lib gtktest.obj
Intel(R) C++ Compiler for 32-bit applications, Version 8.1    Build 20040802Z Package ID: W_CC_P_8.1.018
Copyright (C) 1985-2004 Intel Corporation.  All rights reserved.
30 DAY EVALUATION LICENSE

icl: NOTE: The evaluation period for this product ends on 4-dec-2004 UTC.
Microsoft (R) Incremental Linker Version 7.00.9466
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:gtktest.exe
\gtkwin32\lib\glib-2.0.lib
\gtkwin32\lib\gtk-win32-2.0.lib
\gtkwin32\lib\gobject-2.0.lib
gtktest.obj

E:\eclipse\workspace\GtkTest>;

E:\eclipse\workspace\GtkTest>;make
gcc -I\gtkwin32\include -I\gtkwin32\include\glib-2.0 -I\gtkwin32\include\gtk-2.0 -I\gtkwin32\lib\glib-2.0\include -I\gtkwin32\lib\gtk-2.0\include -I\gtkwin32\include\atk-1.0 -I\gtkwin32\include\pango-1.0 -c gtktest.c
gcc -L\gtkwin32\lib -lglib-2.0 -lgtk-win32-2.0 -lgobject-2.0 gtktest.o -o gtktest.exe
gtktest.o(.text+0x1c):gtktest.c: undefined reference to `g_print'
gtktest.o(.text+0x4b):gtktest.c: undefined reference to `g_print'
gtktest.o(.text+0x60):gtktest.c: undefined reference to `gtk_main_quit'
gtktest.o(.text+0xc2):gtktest.c: undefined reference to `gtk_init_abi_check'
gtktest.o(.text+0xcf):gtktest.c: undefined reference to `gtk_window_new'
gtktest.o(.text+0xf5):gtktest.c: undefined reference to `g_type_check_instance_cast'
gtktest.o(.text+0xfe):gtktest.c: undefined reference to `g_signal_connect_data'
gtktest.o(.text+0x121):gtktest.c: undefined reference to `g_type_check_instance_cast'
gtktest.o(.text+0x12a):gtktest.c: undefined reference to `g_signal_connect_data'
gtktest.o(.text+0x13d):gtktest.c: undefined reference to `gtk_container_get_type'
gtktest.o(.text+0x149):gtktest.c: undefined reference to `g_type_check_instance_cast'
gtktest.o(.text+0x152):gtktest.c: undefined reference to `gtk_container_set_border_width'
gtktest.o(.text+0x162):gtktest.c: undefined reference to `gtk_button_new_with_label'
gtktest.o(.text+0x188):gtktest.c: undefined reference to `g_type_check_instance_cast'
gtktest.o(.text+0x191):gtktest.c: undefined reference to `g_signal_connect_data'
gtktest.o(.text+0x1a8):gtktest.c: undefined reference to `g_type_check_instance_cast'
gtktest.o(.text+0x1b1):gtktest.c: undefined reference to `gtk_widget_destroy'
gtktest.o(.text+0x1c3):gtktest.c: undefined reference to `g_type_check_instance_cast'
gtktest.o(.text+0x1cc):gtktest.c: undefined reference to `g_signal_connect_data'
gtktest.o(.text+0x1e0):gtktest.c: undefined reference to `gtk_container_get_type'
gtktest.o(.text+0x1ec):gtktest.c: undefined reference to `g_type_check_instance_cast'
gtktest.o(.text+0x1f5):gtktest.c: undefined reference to `gtk_container_add'
gtktest.o(.text+0x203):gtktest.c: undefined reference to `gtk_widget_show'
gtktest.o(.text+0x211):gtktest.c: undefined reference to `gtk_widget_show'
gtktest.o(.text+0x219):gtktest.c: undefined reference to `gtk_main'
make: *** [gtktest.exe] Error 1

E:\eclipse\workspace\GtkTest>;

作者: Moonwellatg4    时间: 2004-11-09 16:56
标题: Help!GTK编译问题!
以前我在linux写gtk程序的时候,gcc 加上 `pkg-config --cflags --libs gtk+-2.0`参数就行了。

windows的平台的没有用过。
但是从你出错的提示来看,是头文件的包含问题。

也许应该在gcc的编译命令行上加上 -I 参数,后面跟gtk 头文件的路径。

另外,www.gtk.org 上面应该有详细的说明文档.
作者: Moonwellatg4    时间: 2004-11-09 17:30
标题: Help!GTK编译问题!
On NT/2k/XP, it is possible to have nmake create temporary files containing the output from pkg-config, and use those in a nmake makefile like this:

foobar.exe: foobar.obj __gtk_libs.mak
        cl -MD foobar.obj @__gtk_libs.mak
        @del __gtk_libs.mak

foobar.obj: foobar.c __gtk_cflags.mak
        cl -MD -c @__gtk_cflags.mak foobar.c
        @del __gtk_cflags.mak

__gtk_cflags.mak:
        pkg-config --msvc-syntax --cflags gtk+-2.0 >;$@

__gtk_libs.mak:
        for /F "delims==" %i in ('pkg-config --msvc-syntax --libs gtk+-2.0') \
                do echo /link %i >;$@

Note in the above makefile fragment that the __gtk_libs.mak file is created using the for /F syntax available only in the cmd.exe command interpreter on NT/2k/XP. These obscure acrobatics are needed because we want __gtk_libs.mak to contain a line that starts with /link, but pkg-config cannot output the /link flag itself as a cl command line might contain several invokations of pkg-config --libs. We cannot put the /link on the cl command line that links foobar.exe either, as cl then gets confused and runs the linker with a command file that on one line has @__gtk_libs.mak, and link.exe doesn't like that. Sigh.

相关链接
http://www.gimp.org/~tml/gimp/win32/downloads.html
作者: Joelay    时间: 2004-11-09 20:57
标题: Help!GTK编译问题!
哥们儿,我不是在用msvc编译的时候出的错,是用gcc的时候出的错。同时也不是头文件出错,因为头文件只跟编译时有关,我是在链接的时候出的错。通常这种情况都是没有链接到相关的库,不过郁闷的是通过icl的链接结果就知道,我加载的库是正确的。
作者: jywHltj    时间: 2007-05-22 12:13
用 MinGW(dev-c++ 用 MinGW 做编译环境)要把被编译(或连接)的文件作为放在 -l 选项之前

gcc gtktest.o -L/gtkwin32/lib -lglib-2.0 -lgtk-win32-2.0 -o gtktest.exe

我也遇到了这个问题,没有搜到解决方案,后来自己试发现是这个缘故
作者: connet    时间: 2007-05-23 15:12
gcc -L\gtkwin32\lib -lglib-2.0 -lgtk-win32-2.0 -lgobject-2.0 gtktest.o -o gtktest.exe
显然还差 -lglib-2.0 之类的库
作者: gucuiwen    时间: 2007-07-02 13:28
在CMD窗口下执行命令 pkg-config --cflags --libs gtk+-2.0
然后把这个命令的输出结果作为gcc的参数。
作者: gtk-focus    时间: 2007-07-04 10:04
你应该把要连接的库放到后面
gcc -o gtktest.exe gtktest.o  -L/gtkwin32/lib -lglib-2.0 -lgtk-win32-2.0




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2