2011-04-29 82 views
0

我在尝试在Windows上编译一个简单的GTK + Hello World应用程序。我从这个网址下面的教程:帮助在Windows上使用MinGW编译GTK +

http://pandhare0.tripod.com/#mini-Tutorial

我HelloWorld.c的内容如下,也从一个维基百科例如采取:

#include <gtk/gtk.h> 

int main (int argc, char *argv[]) 
{ 
    GtkWidget *window; 
    GtkWidget *label; 

    gtk_init (&argc, &argv); 

    /* create the main, top level, window */ 
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL); 

    /* give it the title */ 
    gtk_window_set_title (GTK_WINDOW (window), "Hello World"); 

    /* Connect the destroy signal of the window to gtk_main_quit 
    * When the window is about to be destroyed we get a notification and 
    * stop the main GTK+ loop 
    */ 
    g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); 

    /* Create the "Hello, World" label */ 
    label = gtk_label_new ("Hello, World"); 

    /* and insert it into the main window */ 
    gtk_container_add (GTK_CONTAINER (window), label); 

    /* make sure that everything, window and label, are visible */ 
    gtk_widget_show_all (window); 

    /* start the main loop, and let it rest there until the application is closed */ 
    gtk_main(); 

    return 0; 
} 

我按照说明来生成生成bat文件和内容如下:

path C:\MinGW\bin;C:C:\gtk_2_22_x64\lib\%path% 

gcc -Wall -g %1 -o %2 -mno-cygwin -mms-bitfields -IC:C:\gtk_2_22_x64\include\gtk-2.0 -IC:C:\gtk_2_22_x64\lib\gtk-2.0\include -IC:C:\gtk_2_22_x64\include\atk-1.0 -IC:C:\gtk_2_22_x64\include\cairo -IC:C:\gtk_2_22_x64\include\gdk-pixbuf-2.0 -IC:C:\gtk_2_22_x64\include\pango-1.0 -IC:C:\gtk_2_22_x64\include\glib-2.0 -IC:C:\gtk_2_22_x64\lib\glib-2.0\include -IC:C:\gtk_2_22_x64\include\pixman-1 -IC:C:\gtk_2_22_x64\include -IC:C:\gtk_2_22_x64\include\freetype2 -IC:C:\gtk_2_22_x64\include\libpng14 -LC:C:\gtk_2_22_x64\lib -lgtk-win32-2.0 -lgdk-win32-2.0 -latk-1.0 -lgio-2.0 -lpangowin32-1.0 -lgdi32 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lglib-2.0 -lintl 


%2 

我在我的环境路径中有MinGW。当我运行我的命令提示符中以下命令:

gtkcmd.bat HelloWorld.c HelloWorld.exe 

我得到以下输出:

C:\gtk+_compilation>gtkcmd.bat HelloWorld.c HelloWorld.exe 

C:\gtk+_compilation>path C:\MinGW\bin;C:C:\gtk_2_22_x64\lib\C:\MinGW\bin;C:C:\gt 
k_2_22_x64\lib\C:\MinGW\bin;C:C:\gtk_2_22_x64\lib\C:\MinGW\bin;C:C:\gtk_2_22_x64 
\lib\C:\MinGW\bin;C:C:\gtk_2_22_x64\lib\C:\MinGW\bin;C:\gtk_2_22_x64\lib\C:\MinG 
W\bin;C:\gtk_2_22_x64\lib\C:\Program Files\Common Files\Microsoft Shared\Windows 
Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Windo 
ws\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPower 
Shell\v1.0\;C:\Program Files\Dell\Dell Wireless WLAN Card;c:\Program Files (x86) 
\Common Files\Roxio Shared\10.0\DLLShared\;c:\Program Files (x86)\Common Files\R 
oxio Shared\DLLShared\;C:\Program Files\TortoiseSVN\bin;c:\Program Files (x86)\M 
icrosoft SQL Server\90\Tools\binn\;C:\Program Files (x86)\Windows Live\Shared;C: 
\Program Files (x86)\IronPython 2.7;c:\Program Files (x86)\Microsoft ASP.NET\ASP 
.NET Web Pages\v1.0\;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\MinGW\bin;C:\gt 
k_2_22_x64\bin;C:\gtk_2_22_x64\lib 

C:\gtk+_compilation>gcc -Wall -g HelloWorld.c -o HelloWorld.exe -mno-cygwin -mms 
-bitfields -IC:C:\gtk_2_22_x64\include\gtk-2.0 -IC:C:\gtk_2_22_x64\lib\gtk-2.0\i 
nclude -IC:C:\gtk_2_22_x64\include\atk-1.0 -IC:C:\gtk_2_22_x64\include\cairo -IC 
:C:\gtk_2_22_x64\include\gdk-pixbuf-2.0 -IC:C:\gtk_2_22_x64\include\pango-1.0 -I 
C:C:\gtk_2_22_x64\include\glib-2.0 -IC:C:\gtk_2_22_x64\lib\glib-2.0\include -IC: 
C:\gtk_2_22_x64\include\pixman-1 -IC:C:\gtk_2_22_x64\include -IC:C:\gtk_2_22_x64 
\include\freetype2 -IC:C:\gtk_2_22_x64\include\libpng14 -LC:C:\gtk_2_22_x64\lib 
-lgtk-win32-2.0 -lgdk-win32-2.0 -latk-1.0 -lgio-2.0 -lpangowin32-1.0 -lgdi32 -lp 
angocairo-1.0 -lgdk_pixbuf-2.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 - 
lgthread-2.0 -lglib-2.0 -lintl 
HelloWorld.c:1:22: fatal error: gtk/gtk.h: No such file or directory 
compilation terminated. 

C:\gtk+_compilation>HelloWorld.exe 
'HelloWorld.exe' is not recognized as an internal or external command, 
operable program or batch file. 

C:\gtk+_compilation> 

以前我试过,严格教程所说的话,并使用/路径语句而不是我现在使用的完整路径。当我使用/虽然它不能链接任何东西。每个GTK语句都返回一个未定义的错误。所以我一直在命令行中使用标题和链接器语句中的完整路径。正如你从上面看到的,它找不到gtk/gth.h头文件。这让我感到困惑,因为我可以在命令行参数中清楚地看到这些路径。

任何帮助,非常感谢。

干杯,

安德鲁

UPDATE:

好了 - 我没有搞砸bat文件 - 愚蠢的错误,但有一个答案修正,内联后下面我现在有以下蝙蝠文件:

path \MinGW\bin;C:\gtk_2_22_x64\lib\%path% 

gcc -Wall -g %1 -o %2 -mno-cygwin -mms-bitfields -IC:\gtk_2_22_x64\include\gtk-2.0 -IC:\gtk_2_22_x64\lib\gtk-2.0\include -IC:\gtk_2_22_x64\include\atk-1.0 -IC:\gtk_2_22_x64\include\cairo -IC:\gtk_2_22_x64\include\gdk-pixbuf-2.0 -IC:\gtk_2_22_x64\include\pango-1.0 -IC:\gtk_2_22_x64\include\glib-2.0 -IC:\gtk_2_22_x64\lib\glib-2.0\include -IC:\gtk_2_22_x64\include\pixman-1 -IC:\gtk_2_22_x64\include -IC:\gtk_2_22_x64\include\freetype2 -IC:\gtk_2_22_x64\include\libpng14 -LC:\gtk_2_22_x64\lib -lgtk-win32-2.0 -lgdk-win32-2.0 -latk-1.0 -lgio-2.0 -lpangowin32-1.0 -lgdi32 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lglib-2.0 -lintl 


%2 

之后我现在从汇编中得到以下错误:

C:\Users\REA_AN~1\AppData\Local\Temp\cclrbtyP.o: In function `main': 
C:\gtk+_compilation/HelloWorld.c:8: undefined reference to `gtk_init_abi_check' 
C:\gtk+_compilation/HelloWorld.c:11: undefined reference to `gtk_window_new' 
C:\gtk+_compilation/HelloWorld.c:14: undefined reference to `gtk_window_get_type 
' 
C:\gtk+_compilation/HelloWorld.c:14: undefined reference to `g_type_check_instan 
ce_cast' 
C:\gtk+_compilation/HelloWorld.c:14: undefined reference to `gtk_window_set_titl 
e' 
C:\gtk+_compilation/HelloWorld.c:20: undefined reference to `gtk_main_quit' 
C:\gtk+_compilation/HelloWorld.c:20: undefined reference to `g_signal_connect_da 
ta' 
C:\gtk+_compilation/HelloWorld.c:23: undefined reference to `gtk_label_new' 
C:\gtk+_compilation/HelloWorld.c:26: undefined reference to `gtk_container_get_t 
ype' 
C:\gtk+_compilation/HelloWorld.c:26: undefined reference to `g_type_check_instan 
ce_cast' 
C:\gtk+_compilation/HelloWorld.c:26: undefined reference to `gtk_container_add' 
C:\gtk+_compilation/HelloWorld.c:29: undefined reference to `gtk_widget_show_all 
' 
C:\gtk+_compilation/HelloWorld.c:32: undefined reference to `gtk_main' 
collect2: ld returned 1 exit status 

回答

2

看来你folowed说明不正确莫名其妙创建.bat文件 - 这一点:

-IC:C:\gtk_2_22_x64\include\gtk-2.0 

应该是:

-IC:\gtk_2_22_x64\include\gtk-2.0 

和类似的其他地方。它看起来像你的道路已经得到了设置错误 - 这样的:

path C:\MinGW\bin;C:C:\gtk_2_22_x64\lib\%path% 

应该是:

path C:\MinGW\bin;C:\gtk_2_22_x64\lib\%path% 

或类似的东西(注C:C:应该是C :)。

编辑:现在你的问题是,链接器无法找到库。该批处理文件应包含的东西,如:

-L/path/to/gtk/libraries 

,但我不知道你是怎么指定当您创建的文件。

+0

我已经更新了我的问题,并更正了您指出的问题。 +1的更正,谢谢:) – 2011-04-29 11:54:58

+0

这是存在于上面的.bat文件内容。 -LC:\ gtk_2_22_x64 \ lib – 2011-04-29 12:34:13

+0

@REA_哎呀,对不起,我错过了。但是这些肯定是链接器错误,所以看起来它需要的库不是因为某种原因被找到的。 – 2011-04-29 12:43:31

相关问题