帮助在Windows上使用MinGW编译GTK + [英] Help compiling GTK+ on Windows using MinGW
问题描述
我试图在Windows上编译一个简单的GTK + Hello World应用程序。我遵循此网址的教程:
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);
/ *创建主,顶级窗口* /
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
/ *给它标题* /
gtk_window_set_title(GTK_WINDOW(window),Hello World);
/ *将窗口的destroy信号连接到gtk_main_quit
*当窗口即将被销毁时,我们得到一个通知,
*停止主GTK +循环
* /
g_signal_connect(窗口,destroy,G_CALLBACK(gtk_main_quit),NULL);
/ *创建Hello,World标签* /
label = gtk_label_new(Hello,World);
/ *并将其插入主窗口* /
gtk_container_add(GTK_CONTAINER(window),label);
/ *确保所有的东西,窗口和标签可见* /
gtk_widget_show_all(window);
/ *启动主循环,让它停留在那里,直到应用程序关闭* /
gtk_main();
return 0;
}
我按照说明生成构建bat文件,其内容如下:
路径C:\MinGW\bin; C:C:\gtk_2_22_x64 \lib \%路径%
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>路径C:\MinGW\bin; 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文件\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文件\Dell \Dell无线WLAN卡; c:\程序文件(x86)
\Common文件\Roxio共享\10.0 \DLL共享\; c:\程序文件(x86) \Common Files\R
oxio Shared\DLLShared \; C:\Program Files\TortoiseSVN\bin; c:\Program Files(x86)\M
Microsoft 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错误:gtk / gtk.h:没有这样的文件或目录
编译终止。
C:\gtk + _compilation> HelloWorld.exe
'HelloWorld.exe'不能识别为内部或外部命令,
可操作的程序或批处理文件。
C:\gtk + _compilation>
以前,我试过,严格地说教程说,到我现在使用的完整路径。当我使用/虽然它不能链接任何东西。每个GTK语句都返回一个未定义的错误。所以我在命令行的header和linkers语句中使用Full路径。从上面可以看到,它找不到gtk / gth.h头。这让我很困惑,因为我可以清楚地看到这样的命令行参数的路径。
任何帮助是非常感激。
干杯,
Andrew
更新:
好吧 - 我搞砸了bat文件 - daft的错误,但在纠正这些内联回答下面我现在有以下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
之后,我从编译中得到以下错误: / p>
C:\Users\REA_AN〜1\AppData\Local\Temp\cclrbtyP.o:In function 'main':
C:\gtk + _compilation / HelloWorld.c:8:undefined引用`gtk_init_abi_check'
C:\gtk + _compilation / HelloWorld.c:11: gtk_window_new'
C:\gtk + _compilation / HelloWorld.c:14:未定义引用`gtk_window_get_type
'
C:\gtk + _compilation / HelloWorld.c:14:undefined到`g_type_check_instan
ce_cast'
C:\gtk + _compilation / HelloWorld.c:14:未定义引用`gtk_window_set_titl
e'
C:\gtk + _compilation / HelloWorld.c:20:未定义引用`gtk_main_quit'
C:\gtk + _compilation / HelloWorld.c:20:未定义引用`g_signal_connect_da
ta'
C:\gtk + _compilation / HelloWorld.c:23:未定义引用`gtk_label_new'
C:\gtk + _compilation / HelloWorld.c:26:未定义引用`gtk_container_get_t
ype'
C: \gtk + _compilation / HelloWorld.c:26:未定义引用`g_type_check_instan
ce_cast'
C:\gtk + _compilation / HelloWorld.c:26:未定义引用`gtk_container_add'
C:\gtk + _compilation / HelloWorld.c:29:未定义引用`gtk_widget_show_all
'
C:\gtk + _compilation / HelloWorld.c:32:undefined引用`gtk_main'
collect2:ld returned 1 exit status
似乎你错误地创建.bat文件的指令错误地创建 - 这:
-IC:C:\gtk_2_22_x64 \ include\gtk-2.0
应为:
-IC:\gtk_2_22_x64\include\gtk-2.0
和其他地方相似。您的路径设置不正确 -
: 路径C:\MinGW\bin; C:C :\gtk_2_22_x64\lib \%path%
应为:
路径C:\MinGW\bin; C:\gtk_2_22_x64\lib\%path%
或类似的东西(注意C:C:应该是C:)。
修改:现在您的问题是链接器找不到库。批处理文件应包含以下内容:
-L / path / to / gtk / libraries
但我不知道您在创建文件时如何指定。
I am on with trying to compile a simple GTK+ Hello World app on windows. I am following a tutorial from this url:
http://pandhare0.tripod.com/#mini-Tutorial
The contents of my HelloWorld.c is as follows and also taken from a wikipedia example:
#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; }
I have followed the instructions to generate the build bat file and the contents of which are below:
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
I have the MinGW inside my environment path. When I run the following command inside my command prompt:
gtkcmd.bat HelloWorld.c HelloWorld.exe
I get the following output:
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>
Previously I had tried, strictly what the tutorial said, and used the / in the path statements as opposed to the full paths I now use. When I did use the / though it could not link anything. Every GTK statement returned an undefined error. So I have stayed with using the Full path in the header and linkers statements in the command line. As you can see from the above, it cannot find the gtk/gth.h header. This confuses me as I can clearly see the paths for such inside the command line arguments.
Any help is greatly appreciated.
Cheers,
Andrew
UPDATE:
Ok - I did screw up the bat file - daft mistakes but after correcting these inline with an answer below I now have the following bat file:
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
After this I now get the following errors from the compilation:
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
解决方案It seems you folowed the instructions to create the .bat file incorrectly somehow - this:
-IC:C:\gtk_2_22_x64\include\gtk-2.0
should be:
-IC:\gtk_2_22_x64\include\gtk-2.0
and similar elsewhere. It looks like your path has got set up incorrectly - this:
path C:\MinGW\bin;C:C:\gtk_2_22_x64\lib\%path%
should be:
path C:\MinGW\bin;C:\gtk_2_22_x64\lib\%path%
or something like it (note C:C: should be C:).
Edit: And now your problem is that the linker cannot find the libraries. The batch file should contain stuff like:
-L/path/to/gtk/libraries
but I don't know how you specify that when you create the file.
这篇关于帮助在Windows上使用MinGW编译GTK +的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!