帮助在Windows上使用MinGW编译GTK+
Help compiling GTK+ on Windows using MinGW
我正在尝试在windows上编译一个简单的GTK+ Hello World应用程序。我正在遵循这个url的教程:
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;
}
我已经按照说明生成了build bat文件,其内容如下:
path C:MinGWbin;C:C:gtk_2_22_x64lib%path%
gcc -Wall -g %1 -o %2 -mno-cygwin -mms-bitfields -IC:C:gtk_2_22_x64includegtk-2.0 -IC:C:gtk_2_22_x64libgtk-2.0include -IC:C:gtk_2_22_x64includeatk-1.0 -IC:C:gtk_2_22_x64includecairo -IC:C:gtk_2_22_x64includegdk-pixbuf-2.0 -IC:C:gtk_2_22_x64includepango-1.0 -IC:C:gtk_2_22_x64includeglib-2.0 -IC:C:gtk_2_22_x64libglib-2.0include -IC:C:gtk_2_22_x64includepixman-1 -IC:C:gtk_2_22_x64include -IC:C:gtk_2_22_x64includefreetype2 -IC:C:gtk_2_22_x64includelibpng14 -LC:C:gtk_2_22_x64lib -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:MinGWbin;C:C:gtk_2_22_x64libC:MinGWbin;C:C:gt
k_2_22_x64libC:MinGWbin;C:C:gtk_2_22_x64libC:MinGWbin;C:C:gtk_2_22_x64
libC:MinGWbin;C:C:gtk_2_22_x64libC:MinGWbin;C:gtk_2_22_x64libC:MinG
Wbin;C:gtk_2_22_x64libC:Program FilesCommon FilesMicrosoft SharedWindows
Live;C:Program Files (x86)Common FilesMicrosoft SharedWindows Live;C:Windo
wssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPower
Shellv1.0;C:Program FilesDellDell Wireless WLAN Card;c:Program Files (x86)
Common FilesRoxio Shared10.0DLLShared;c:Program Files (x86)Common FilesR
oxio SharedDLLShared;C:Program FilesTortoiseSVNbin;c:Program Files (x86)M
icrosoft SQL Server90Toolsbinn;C:Program Files (x86)Windows LiveShared;C:
Program Files (x86)IronPython 2.7;c:Program Files (x86)Microsoft ASP.NETASP
.NET Web Pagesv1.0;C:Program Files (x86)GtkSharp2.12bin;C:MinGWbin;C:gt
k_2_22_x64bin;C:gtk_2_22_x64lib
C:gtk+_compilation>gcc -Wall -g HelloWorld.c -o HelloWorld.exe -mno-cygwin -mms
-bitfields -IC:C:gtk_2_22_x64includegtk-2.0 -IC:C:gtk_2_22_x64libgtk-2.0i
nclude -IC:C:gtk_2_22_x64includeatk-1.0 -IC:C:gtk_2_22_x64includecairo -IC
:C:gtk_2_22_x64includegdk-pixbuf-2.0 -IC:C:gtk_2_22_x64includepango-1.0 -I
C:C:gtk_2_22_x64includeglib-2.0 -IC:C:gtk_2_22_x64libglib-2.0include -IC:
C:gtk_2_22_x64includepixman-1 -IC:C:gtk_2_22_x64include -IC:C:gtk_2_22_x64
includefreetype2 -IC:C:gtk_2_22_x64includelibpng14 -LC:C:gtk_2_22_x64lib
-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头文件。这让我很困惑,因为我可以清楚地看到命令行参数中的路径。
感谢您的帮助。
欢呼,安德鲁
更新:
Ok -我确实搞砸了bat文件-愚蠢的错误,但在纠正这些内联的答案之后,我现在有以下bat文件:
path MinGWbin;C:gtk_2_22_x64lib%path%
gcc -Wall -g %1 -o %2 -mno-cygwin -mms-bitfields -IC:gtk_2_22_x64includegtk-2.0 -IC:gtk_2_22_x64libgtk-2.0include -IC:gtk_2_22_x64includeatk-1.0 -IC:gtk_2_22_x64includecairo -IC:gtk_2_22_x64includegdk-pixbuf-2.0 -IC:gtk_2_22_x64includepango-1.0 -IC:gtk_2_22_x64includeglib-2.0 -IC:gtk_2_22_x64libglib-2.0include -IC:gtk_2_22_x64includepixman-1 -IC:gtk_2_22_x64include -IC:gtk_2_22_x64includefreetype2 -IC:gtk_2_22_x64includelibpng14 -LC:gtk_2_22_x64lib -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:UsersREA_AN~1AppDataLocalTempcclrbtyP.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
似乎您按照说明不正确地创建了.bat文件-这:
-IC:C:gtk_2_22_x64includegtk-2.0
应:-IC:gtk_2_22_x64includegtk-2.0
和其他类似的。看起来你的路径设置不正确- this:
path C:MinGWbin;C:C:gtk_2_22_x64lib%path%
应:path C:MinGWbin;C:gtk_2_22_x64lib%path%
或类似的东西(注意C:C:应该是C:)。
Edit:现在你的问题是链接器找不到库。批处理文件应该包含如下内容:
-L/path/to/gtk/libraries
但是我不知道你在创建文件的时候是怎么指定的
相关文章:
- 尝试在Windows上执行C++时出错(通过MinGW编译)
- 如何使用mingw编译C STD ::线程代码
- MinGW 编译的可执行文件与网络无法在 x64 系统上运行
- MinGW编译的exe-缺少libgcc_s_silj-1.dll
- 使用由 Mingw 5.3 编译的 boost ASIO 库使用 QT 时出错
- 如何在 Atom IDE 中使用 gpp-compiler 时更改 MinGW 编译的 exe 位置?
- mingw 编译错误:从 'FARPROC ' 到 'void*' 的转换无效,但 msvc 编译正常
- 使用 MinGW 编译具有网络代码的简单 C++ SFML 文件会引发错误"undefined reference to IpAddress"
- 使用 mingw 编译 opencv3.1
- libx264用mingw编译 - 缺少__umoddi3,__udivdi3,_fseeko64和____chkstk
- MinGW .h 编译文件不起作用:此文件的版本与您运行的 Windows 版本不兼容
- 尝试使用 MinGW 编译 Assembly + C++:ccqKAvXJ.o:main.cpp:(.text+0x18):对 'GetMagicNumber' 的未定义引用
- std::endl 导致使用 MinGW 编译的 Windows 8 崩溃
- 用mingw编译SDL2,使用崇高的文本2错误
- MinGW编译失败:我创建的头文件没有这样的文件或目录
- 获取记事本++以使用minGW编译和运行C++程序
- 使用小型转储和 GDB 分析崩溃,以便 mingw 编译的可执行文件
- 使用 MinGW 编译自动化代理
- 无法在Win7上使用MinGW编译RIES。
- Qt5:此代码使用msvc2012编译正常,但使用MinGW编译时出现错误..为什么?