有人可以帮我在Vista cmd提示符下编译gtk +(& gtkmm)吗? 我最近试过&不能让这个工作。我觉得我的所有依赖关系和路径都是正确的,但我显然没有或错过了什么!我已经搜索过互联网,但没有找到具体的帮助(我也尝试在cygwin中编译 - 但已成功编译并在MSYS中运行简单的helloworld gtk +示例)。
我通过MinGW& amp; Gtk + Win32 dev(Glade)&安装了Gtkmm Win32。以下是一些示例cmd提示输出,以显示我遇到的问题:
D:\RPD_Programming\RPD_HelloWorld\RPD_Gtk_helloworld>gcc helloworld.c -o hellowo
rld
helloworld.c:1:21: gtk/gtk.h: No such file or directory
helloworld.c:5: error: syntax error before '*' token
helloworld.c:11: error: syntax error before "delete_event"
helloworld.c:11: error: syntax error before '*' token
helloworld.c: In function `delete_event':
helloworld.c:26: error: `TRUE' undeclared (first use in this function)
helloworld.c:26: error: (Each undeclared identifier is reported only once
helloworld.c:26: error: for each function it appears in.)
helloworld.c: At top level:
helloworld.c:30: error: syntax error before '*' token
helloworld.c: In function `main':
helloworld.c:40: error: `GtkWidget' undeclared (first use in this function)
helloworld.c:40: error: `window' undeclared (first use in this function)
helloworld.c:41: error: `button' undeclared (first use in this function)
helloworld.c:48: error: `GTK_WINDOW_TOPLEVEL' undeclared (first use in this func
tion)
helloworld.c:56: error: `NULL' undeclared (first use in this function)
helloworld.c:80: error: `gtk_widget_destroy' undeclared (first use in this funct
ion)
D:\RPD_Programming\RPD_HelloWorld\RPD_Gtk_helloworld>gcc helloworld.c -o hellowo
rld pkg-config --cflags --libs gtk+-2.0
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:\RPD_Programming\RPD_HelloWorld\RPD_Gtk_helloworld>gcc --v
Reading specs from C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/specs
Configured with: ../gcc-3.4.5-20060117-3/configure --with-gcc --with-gnu-ld --wi
th-gnu-as --host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --dis
able-nls --enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry --d
isable-shared --enable-sjlj-exceptions --enable-libgcj --disable-java-awt --with
out-x --enable-java-gc=boehm --disable-libgcj-debug --enable-interpreter --enabl
e-hash-synchronization --enable-libstdcxx-debug
Thread model: win32
gcc version 3.4.5 (mingw-vista special r3)
D:\RPD_Programming\RPD_HelloWorld\RPD_Gtk_helloworld>pkg-config --version
0.23
D:\RPD_Programming\RPD_HelloWorld\RPD_Gtk_helloworld>which pkg-config
/cygdrive/c/Gtk+/bin/pkg-config
D:\RPD_Programming\RPD_HelloWorld\RPD_Gtk_helloworld> echo %PKG_CONFIG_PATH%
C:\Gtk+\lib\pkgconfig
pkg-config安装好吗?我使用正确的编译命令语法吗? 我可以使用MS vis C express编译器(或任何MSWindows7 SDK编译器 - 因为我也安装了它?!)。我只是一个初学者/业余程序员,但是想要编写用于GUI编程的gtk + / gtkmm代码,并希望能够在cmd提示符下编译以及使用IDE进行编码和编程。编译/运行。
我很感激并期待有用的回复,非常感谢
答案 0 :(得分:0)
我强烈推荐CMake完成这项任务。是的我知道这不是你问的,但你甚至没有使用makefile。虽然我确信可以将一些命令组合在一起使其工作但这并不实用。 CMake内置了模块,用于生成makefile并在您需要的窗口上查找gtkmm库。它甚至可以生成MSVC项目或mingw / msys makefile。
话虽这么说,如果你坚持努力,在gtkmm.pc文件上使用--cflags运行pkg-config,并将输出COPY PASTE输出到.bat文件中。我不知道将pkg-config嵌入到windows命令行中的任何其他方法。 (我实际上这样做了一次,它起作用了)
但严重的是,cmake旨在解决问题,而且它是FOSS。
答案 1 :(得分:0)
D:\RPD_Programming\RPD_HelloWorld\RPD_Gtk_helloworld>gcc helloworld.c -o hellowo
rld pkg-config --cflags --libs gtk+-2.0
您需要将pkg-config的输出作为命令的一部分,如下所示:
gcc helloworld.c -o helloworld.exe `pkg-config --cflags --libs gtk+-2.0`
还要确保已正确安装和配置pkg-config。
helloworld.c:1:21: gtk/gtk.h: No such file or directory
这表明您在库路径中没有GTK标题
答案 2 :(得分:0)
我从这个互联网论坛找到了另一种解决方案: gtk forum -dreblen
为pkg-config制作这些env变量--cflags& pkg-config --libs gtk + -2.0并将它们组合到一个新的env var%GTK_COMPILE%并且包括在Vista cmd shell的命令行中已经工作并且编译完成并且.exe gui窗口helloworld运行。
我仍然不知道为什么我的pkg版本来自MinGW目录和我的pkg-config path是C:\ Gtk + \ lib \ pkgconfig。
这仍然不是我预期的答案,我仍然觉得应该有另一种(更好/更合适)的方式在Vista中使用gtk +在cmd提示符下完全使用pkg-config以获得成功的编译和运行。也许有一天我会理解这一点!
答案 3 :(得分:0)
使用cmd.exe中的pkg-config确实很痛苦,因为使用它的“正常”方式是在Unix中的反引号或反引号(`thingies,ASCII反引号,不要称它们为“反斜杠”)风格贝壳。如果您坚持只使用cmd.exe,则需要执行一些cmd.exe杂技以将pkg-config的输出放入命令行。或者只是手动运行pkg-config并将其输出复制/粘贴到执行构建的.bat文件中。
无论如何,要记住的一件重要事情是,每当你看到同时使用--cflags和--libs选项运行pkg-config时的常见模因(如LiraNuna上面的回答),不适用于Windows。
给gcc(和cl,就此而言)的参数顺序是很重要。在引用它们的对象(或源)文件之后,库应该
。(它恰好通常在Linux和其他基于ELF的系统上随机工作,因为那里的可执行文件可能包含未定义的符号。)
因此,如果你在env var FOO_CFLAGS中输出pkg-config --cflags foo,并且在env var FOO_LIBS中输出pkg-config --libs foo,那么运行gcc的正确方法是
gcc %CFLAGS% -o myprog.exe %FOO_CFLAGS% myprog.c %FOO_LIBS% %LIBS%
其中CFLAGS是您想要使用的任何其他编译器标志,LIBS是您需要的任何其他库。当然,根据需要添加更多源文件或目标文件。
答案 4 :(得分:0)
我已经提交了一个相关的解决方案(针对Windows上的Eclipse)here
这很费劲,但确实有效!