系统:Windows7,32位,GTK 2.24.10,mingw
我正在尝试编写基本的helloworld.c类型的基于GTK的应用程序 . 但是,它没有运行 .
这些是我遵循的步骤 .
-
安装MinGW .
-
将GTK全部下载到一个包中 .
-
在C:\ gtk文件夹中提取内容 .
-
打开cmd并转到C:\ gtk \ bin目录并运行pkg-config --cflags --libs gtk -win32-2.0
-
它打印编译标志列表,以及将项目链接到的库 . 复制它们并创建一个浴室文件,如下所示 . 设置VAR = FLAGS start cmd,其中VAR = GTK,FLAGS =上一个命令的输出(pkg-config) . 当您要编译文件使用命令时:gcc foo.c%VAR%
D:\ gtk> gcc -o project helloworld.c%GTK%
gcc:%GTK%:没有这样的文件或目录helloworld.c:1:21:错误:gtk / gtk.h:没有这样的文件或目录helloworld.c:在函数'main':helloworld.c:5:错误:'GtkWidget'未声明(首次在此函数中使用)helloworld.c:5:错误:(每个未声明的标识符只报告一次helloworld.c:5:错误:对于它出现的每个函数 . )helloworld.c:5:错误:'window' undeclared(首次使用此函数)helloworld.c:9:错误:'GTK_WINDOW_TOPLEVEL'未声明(首次使用此函数)
D:\gtk>gcc -Wall -g helloworld.c -o helloworld pkg-config --cflags gtk+-2.0 pkg-config --libs gtk+-2.0
gcc: pkg-config: No such file or directory
gcc: gtk+-2.0: No such file or directory
gcc: pkg-config: No such file or directory
gcc: gtk+-2.0: No such file or directory
cc1.exe: error: unrecognized command line option "-fcflags"
cc1.exe: error: unrecognized command line option "-flibs"
D:\ gtk中的批处理文件
set GTK=-mms-bitfields -IC:/gtk/include/gtk-2.0 -IC:/gtk/lib/gtk-2.0/include -IC:/gtk/include/atk-1.0 -IC:/gtk/include/cairo -IC:/gtk/include/gdk-pixbuf-2.0 -IC:/gtk/include/pango-1.0 -IC:/gtk/include/glib-2.0 -IC:/gtk/lib/glib-2.0/include -IC:/gtk/include -IC:/gtk/include/freetype2 -IC:/gtk/include/libpng14 -LC:/gtk/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
start cmd
helloworld.c
#include <gtk/gtk.h>
int main( int argc,
char *argv[] )
{
GtkWidget *window;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_show (window);
gtk_main ();
return 0;
}
3 回答
您可以尝试以下手动步骤:
1) At your command prompt run the pkg-config command to get your include flags:
c:\dev\gtk224\bin\pkg-config.exe --cflags gtk+-2.0
这是我的输出:
2) set the output from (1) to a variable GTK_INCLUDES:
(确保使用步骤(1)中的输出)
3) do the same as step 1 for the library flags:
c:\dev\gtk224\bin\pkg-config.exe --libs gtk+-2.0
这是我的输出:
4) set output from (3) to a variable GTK_LIBS
(确保使用步骤(3)中的输出)
5) make sure gtk+ and MinGW are on your path:
(确保你设置你的mingw和gtk目录的路径)
6) compile:
7) when you are able to compile OK, copy what you did in steps 2,4,5 and 6 to a batch file so can compile you app just by running the batch file.
错误就在这里 .
pkg-config
是一个帮助(我强烈建议)确定链接和lib标志的实用程序 . 你得到的问题是 gcc interprets it as a parameter if you pass them like you do - 你需要在 subshell (但我不知道如何在windows shell或cygwin下执行此操作)在bash下执行它们是$(pkconfig --libs gtk-2.0)
或者使用反引号代替$(...)
运行hello,world程序时会出现同样的错误 . 以下解决方案为我工作 .
而不是在任何地方保存你的
helloworld.c
,把它放在里面MinGW> msys> 1.0> home>“您的主文件夹的名称”> helloworld.c
现在,打开
msys.bat
并编写命令来运行程序 . 在我的情况下它是:它对我有用!