帮助在Windows上使用MinGW的编译GTK + [英] Help compiling GTK+ on Windows using MinGW

查看:202
本文介绍了帮助在Windows上使用MinGW的编译GTK +的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Windows上编译一个简单的GTK +的Hello World程序是对。我从这个网址下面的教程:

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

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

 的#include< GTK / gtk.h> INT主(INT ARGC,CHAR *的argv [])
 {
    * GtkWidget的窗口;
    * GtkWidget的标签;    gtk_init(安培; ARGC,&安培; argv的);    / *创建主,顶层,窗户* /
    窗口= gtk_window_new(GTK_WINDOW_TOPLEVEL);    / *给它的标题* /
    gtk_window_set_title(GTK_WINDOW(窗口),的Hello World);    / *连接窗口的破坏信号gtk_main_quit
     *当窗口即将被摧毁,我们得到一个通知,
     *停止主GTK +循环
     * /
    g_signal_connect(窗口,消灭,G_CALLBACK(gtk_main_quit),NULL);    / *创建你好,世界的标签* /
    标签= gtk_label_new(你好,世界);    / *并将其插入到主窗口* /
    gtk_container_add(GTK_CONTAINER(窗口),标签);    / *确保一切,窗口和标签,可见* /
    gtk_widget_show_all(窗口);    / *启动主循环,让它休息,直到关闭应用程序* /
    进入主循环();    返回0;
 }

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

 路径C:\\ MinGW的\\ BIN; C:C:\\ gtk_2_22_x64 \\ LIB \\%PATH%GCC -Wall -g%1%-o 2 -mno-cygwin的-mms-位域-IC:C:\\ gtk_2_22_x64 \\包括\\ GTK的2.0 -IC:C:\\ gtk_2_22_x64 \\ LIB \\ GTK的2.0 \\包括-IC: C:\\ gtk_2_22_x64 \\包括\\ ATK-1.0 -IC:C:\\ gtk_2_22_x64 \\ \\包括开罗-IC:C:\\ gtk_2_22_x64 \\包括\\ GDK-pixbuf的-2.0 -IC:C:\\ gtk_2_22_x64 \\包括\\攀高 -  1.0  - IC:C:\\ gtk_2_22_x64 \\包括\\巧舌如簧-2.0 -IC:C:\\ gtk_2_22_x64 \\ LIB \\巧舌如簧-2.0 \\包括-IC:C:\\ gtk_2_22_x64 \\包括\\ pixman-1 -IC:C:\\ gtk_2_22_x64 \\包括 - IC:C:\\ gtk_2_22_x64 \\包括\\对FreeType2 -IC:C:\\ gtk_2_22_x64 \\包括\\ 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.exe的HelloWorld.c

我得到以下的输出:

  C:\\ GTK + _compilation> gtkcmd.bat HelloWorld.exe的HelloWorld.cC:\\ GTK + _compilation>路径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:\\明
W¯¯\\ BIN; C:\\ gtk_2_22_x64 \\ lib目录\\ C:\\ Program Files文件\\ Common Files文件\\ Microsoft共享\\的Windows
 住; C:\\ Program Files文件(x86)的\\ Common Files文件\\ Microsoft共享\\的Windows Live; C:\\的Windo
WS \\ SYSTEM32; C:\\ WINDOWS; C:\\ WINDOWS \\ SYSTEM32 \\ WBEM; C:\\ WINDOWS \\ SYSTEM32 \\ WindowsPower
壳牌\\ 1.0 \\; C:\\ Program Files文件\\戴尔\\ DELL无线网卡; C:\\ Program Files文件(86)
\\ Common Files文件\\ Roxio的共享\\ 10.0 \\ DLLShared \\; C:\\ Program Files文件(x86)的\\ Common Files文件\\ r
oxio共享\\ DLLShared \\; C:\\ Program Files文件\\ TortoiseSVN的\\ BIN; C:\\ Program Files文件(x86)的\\中号
icrosoft的SQL Server \\ 90 \\ TOOLS \\ BINN \\; C:\\ Program Files文件(x86)的\\的Windows Live \\共享; C:
\\程序文件(x86)\\ IronPython的2.7; C:\\ Program Files文件(x86)的\\微软ASP.NET \\ ASP
.NET Web页\\ 1.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 -o HelloWorld.c HelloWorld.exe的-mno-cygwin的-mms
-bitfields -IC:C:\\ gtk_2_22_x64 \\包括\\ GTK的2.0 -IC:C:\\ gtk_2_22_x64 \\ LIB \\ GTK的2.0 \\我
nclude -IC:C:\\ gtk_2_22_x64 \\包括\\ ATK-1.0 -IC:C:\\ gtk_2_22_x64 \\ \\包括开罗-IC
:C:\\ gtk_2_22_x64 \\包括\\ GDK-pixbuf的-2.0 -IC:C:\\ gtk_2_22_x64 \\包括\\攀高,1.0 -I
C:C:\\ gtk_2_22_x64 \\包括\\巧舌如簧-2.0 -IC:C:\\ gtk_2_22_x64 \\ LIB \\巧舌如簧-2.0 \\包括-IC:
C:\\ gtk_2_22_x64 \\包括\\ pixman-1 -IC:C:\\ gtk_2_22_x64 \\包括-IC:C:\\ gtk_2_22_x64
\\包括\\对FreeType2 -IC:C:\\ gtk_2_22_x64 \\包括\\ 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:致命错误:GTK / gtk.h:没有这样的文件或目录
编译终止。C:\\ GTK + _compilation> HelloWorld.exe的
'HelloWorld.exe的不被识别为内部或外部的命令,
可运行的程序或批处理文件。C:\\ GTK + _compilation>

previously我试过,严格教程所说的话,并在相对于完整路径我现在使用的路径语句使用/。当我做使用/,虽然它不能连接任何东西。每一个GTK语句返回一个未定义的错误。所以,我住在在命令行头和连接器语句中使用的完整路径。正如你可以从上面看到,它找不到GTK / gth.h头。这混淆了我,我可以清楚地看到命令行参数里面这样的路径。

任何帮助是极大AP preciated。

干杯,

安德鲁

更新:

确定 - 我没有搞砸bat文件 - 愚蠢的错误,但有一个答案纠正这些内嵌后低于我现在有以下bat文件:

 路径\\ MinGW的\\ BIN; C:\\ gtk_2_22_x64 \\ LIB \\%PATH%GCC -Wall -g%1%-o 2 -mno-cygwin的-mms-位域-IC:\\ gtk_2_22_x64 \\包括\\ GTK的2.0 -IC:\\ gtk_2_22_x64 \\ LIB \\ GTK的2.0 \\包括-IC:\\ gtk_2_22_x64 \\包括\\ ATK-1.0 -IC:\\ gtk_2_22_x64 \\ \\包括开罗-IC:\\ gtk_2_22_x64 \\包括\\ GDK-pixbuf的-2.0 -IC:\\ gtk_2_22_x64 \\包括\\攀高-1.0 -IC:\\ gtk_2_22_x64 \\包括\\巧舌如簧-2.0 -IC :\\ gtk_2_22_x64 \\ LIB \\巧舌如簧-2.0 \\包括-IC:\\ gtk_2_22_x64 \\包括\\ pixman-1 -IC:\\ gtk_2_22_x64 \\包括-IC:\\ gtk_2_22_x64 \\包括\\对FreeType2 -IC:\\ gtk_2_22_x64 \\包括\\ 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:\\用户\\ REA_AN〜1 \\应用程序数据\\本地的\\ Temp \\ cclrbtyP.o:在函数'主':
C:\\ GTK + _compilation / HelloWorld.c:8:未定义引用`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:未定义的引用`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:未定义的参考`进入主循环
collect2:劳工处返回1退出状态


解决方案

看来你folowed说明创建.bat文件不知何故错误 - 这样的:

  -IC:C:\\ gtk_2_22_x64 \\包括\\ GTK-2.0

应该是:

  -IC:\\ gtk_2_22_x64 \\包括\\ 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 /路径/要/ GTK /库

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

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆