如何在没有 MSYS 的情况下将 gtkmm 与 MinGW (g++) 一起使用?

Posted

技术标签:

【中文标题】如何在没有 MSYS 的情况下将 gtkmm 与 MinGW (g++) 一起使用?【英文标题】:How can I use gtkmm with MinGW (g++) without MSYS? 【发布时间】:2010-05-20 13:49:34 【问题描述】:

这是我的问题的故事:

我离线安装了 MinGW 以及所有必需的软件包(完整安装)。我安装了 Apache 服务器并复制了所有 .tar.gz 文件,并创建了一个名为 sourceforge.org [localhost] 的网站,并在 Windows XP 上自动安装了 MinGW。之后,我设置了 PATH 变量。

我为 MinGW (g++) 安装了 gtkmm。我试图用 gtkmm + MinGW 编译一个简单的窗口,但它不起作用。

我使用这个命令行:

g++ simple.cc -o simple `pkg-config gtkmm-2.4 --cflags --libs`

在此之后,我安装了 MSYS,我可以使用 MSYS 编译 simple.cc,使用这个命令行:

g++ simple.cc -o simple `pkg-config gtkmm-2.4 --cflags --libs`

我的问题: 我想在没有 MSYS 的情况下编译 simple.cc。我想用 cmd.exe 编译我的simple.cc - 这可能吗?如是。怎么样?


base.cc 源代码:

#include <gtkmm.h>
int main(int argc, char *argv[])

Gtk::Main kit(argc, argv);
Gtk::Window window;
Gtk::Main::run(window);
return 0;

命令行:

pkg-config gtkmm-2.4 --cflags --libs

结果:

-mms-bitfields -IC:/gtkmm/include/gtkmm-2.4 -IC:/gtkmm/lib/gtkmm-2.4/include -IC:/gtkmm/include/giomm-2.4-IC:/gtkmm/lib/giomm-2.4/include -IC:/gtkmm/include/pangomm-1.4 -IC:/gtkmm/lib/pangomm-1.4/include -IC:/gtkmm/include/gtk-2.0 -IC:/gtkmm/include/atkmm-1.6 -IC:/gtkmm/include/gdkmm-2.4 -IC:/gtkmm/lib/gdkmm-2.4/include -IC:/gtkmm/include/glibmm-2.4 -IC:/gtkmm/lib/glibmm-2.4/include -IC:/gtkmm/include/glib-2.0 -IC:/gtkmm/lib/glib-2.0/include -IC:/gtkmm/include/sigc++-2.0 -IC:/gtkmm/lib/sigc++-2.0/include -IC:/gtkmm/include/cairomm-1.0 -IC:/gtkmm/lib/cairomm-1.0/include -IC:/gtkmm/include/pango-1.0 -IC:/gtkmm/include/cairo -IC:/gtkmm/include/freetype2 -IC:/gtkmm/include -IC:/gtkmm/include/libpng14 -IC:/gtkmm/lib/gtk-2.0/include -IC:/gtkmm/include/atk-1.0  -LC:/gtkmm/lib -lgtkmm-2.4 -latkmm-1.6 -lgdkmm-2.4 -lgiomm-2.4 -lpangomm-1.4 -lgtk-win32-2.0 -lglibmm-2.4 -lcairomm-1.0 -lsigc-2.0 -lgdk-win32-2.0 -latk-1.0 -lgio-2.0 -lgdk_pixbuf-2.0 -lpangowin32-1.0 -lgdi32 -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0-lgthread-2.0 -lglib-2.0 -lintl

命令行:

g++ base.cc -o base `pkg-config gtkmm-2.4 --cflags --libs`

结果:

g++: `pkg-config: No such file or directory
g++: gtkmm-2.4: No such file or directory
cc1plus.exe: error: unrecognized command line option "-fcflags"
cc1plus.exe: error: unrecognized command line option "-flibs`"

命令行:

g++ base.cc -o base -D_REENTRANT -IC:/gtkmm/include/gtkmm-2.4 -IC:/gtkmm/lib/gtkmm-2.4/include -IC:/gtkmm/include/giomm-2.4-IC:/gtkmm/lib/giomm-2.4/include -IC:/gtkmm/include/pangomm-1.4 -IC:/gtkmm/lib/pangomm-1.4/include -IC:/gtkmm/include/gtk-2.0 -IC:/gtkmm/include/atkmm-1.6 -IC:/gtkmm/include/gdkmm-2.4 -IC:/gtkmm/lib/gdkmm-2.4/include -IC:/gtkmm/include/glibmm-2.4 -IC:/gtkmm/lib/glibmm-2.4/include -IC:/gtkmm/include/glib-2.0 -IC:/gtkmm/lib/glib-2.0/include -IC:/gtkmm/include/sigc++-2.0 -IC:/gtkmm/lib/sigc++-2.0/include -IC:/gtkmm/include/cairomm-1.0 -IC:/gtkmm/lib/cairomm-1.0/include -IC:/gtkmm/include/pango-1.0 -IC:/gtkmm/include/cairo -IC:/gtkmm/include/freetype2 -IC:/gtkmm/include -IC:/gtkmm/include/libpng14 -IC:/gtkmm/lib/gtk-2.0/include -IC:/gtkmm/include/atk-1.0  -LC:/gtkmm/lib -lgtkmm-2.4 -latkmm-1.6 -lgdkmm-2.4 -lgiomm-2.4 -lpangomm-1.4 -lgtk-win32-2.0 -lglibmm-2.4 -lcairomm-1.0 -lsigc-2.0 -lgdk-win32-2.0 -latk-1.0 -lgio-2.0 -lgdk_pixbuf-2.0 -lpangowin32-1.0 -lgdi32 -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0-lgthread-2.0 -lglib-2.0 -lintl

结果: 许多错误看起来像:

C:/gtkmm/include/gtkmm-2.4/gtkmm/statusicon.h:269: error: ISO C++ forbids declar
ation of `get_icon' with no type
C:/gtkmm/include/gtkmm-2.4/gtkmm/statusicon.h:589: error: `Gio' has not been dec
lared
C:/gtkmm/include/gtkmm-2.4/gtkmm/statusicon.h:589: error: `Icon' was not declare
d in this scope
C:/gtkmm/include/gtkmm-2.4/gtkmm/statusicon.h:589: error: template argument 1 is
 invalid
C:/gtkmm/include/gtkmm-2.4/gtkmm/statusicon.h:589: error: template argument 1 is
 invalid
C:/gtkmm/include/gtkmm-2.4/gtkmm/statusicon.h:589: error: ISO C++ forbids declar
ation of `property_gicon' with no type
C:/gtkmm/include/gtkmm-2.4/gtkmm/statusicon.h:599: error: `Gio' has not been dec
lared
C:/gtkmm/include/gtkmm-2.4/gtkmm/statusicon.h:599: error: `Icon' was not declare
d in this scope
C:/gtkmm/include/gtkmm-2.4/gtkmm/statusicon.h:599: error: template argument 1 is
 invalid
C:/gtkmm/include/gtkmm-2.4/gtkmm/statusicon.h:599: error: template argument 1 is
 invalid
C:/gtkmm/include/gtkmm-2.4/gtkmm/statusicon.h:599: error: ISO C++ forbids declar
ation of `property_gicon' with no type

命令行:

g++ base.cc -o base -mms-bitfields -IC:/gtkmm/include/gtkmm-2.4 -IC:/gtkmm/lib/gtkmm-2.4/include -IC:/gtkmm/include/giomm-2.4-IC:/gtkmm/lib/giomm-2.4/include -IC:/gtkmm/include/pangomm-1.4 -IC:/gtkmm/lib/pangomm-1.4/include -IC:/gtkmm/include/gtk-2.0 -IC:/gtkmm/include/atkmm-1.6 -IC:/gtkmm/include/gdkmm-2.4 -IC:/gtkmm/lib/gdkmm-2.4/include -IC:/gtkmm/include/glibmm-2.4 -IC:/gtkmm/lib/glibmm-2.4/include -IC:/gtkmm/include/glib-2.0 -IC:/gtkmm/lib/glib-2.0/include -IC:/gtkmm/include/sigc++-2.0 -IC:/gtkmm/lib/sigc++-2.0/include -IC:/gtkmm/include/cairomm-1.0 -IC:/gtkmm/lib/cairomm-1.0/include -IC:/gtkmm/include/pango-1.0 -IC:/gtkmm/include/cairo -IC:/gtkmm/include/freetype2 -IC:/gtkmm/include -IC:/gtkmm/include/libpng14 -IC:/gtkmm/lib/gtk-2.0/include -IC:/gtkmm/include/atk-1.0  -LC:/gtkmm/lib -lgtkmm-2.4 -latkmm-1.6 -lgdkmm-2.4 -lgiomm-2.4 -lpangomm-1.4 -lgtk-win32-2.0 -lglibmm-2.4 -lcairomm-1.0 -lsigc-2.0 -lgdk-win32-2.0 -latk-1.0 -lgio-2.0 -lgdk_pixbuf-2.0 -lpangowin32-1.0 -lgdi32 -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0-lgthread-2.0 -lglib-2.0 -lintl

结果: 许多错误看起来像:

C:/gtkmm/include/gtkmm-2.4/gtkmm/statusicon.h:269: error: ISO C++ forbids declar
ation of `get_icon' with no type
C:/gtkmm/include/gtkmm-2.4/gtkmm/statusicon.h:589: error: `Gio' has not been dec
lared
C:/gtkmm/include/gtkmm-2.4/gtkmm/statusicon.h:589: error: `Icon' was not declare
d in this scope
C:/gtkmm/include/gtkmm-2.4/gtkmm/statusicon.h:589: error: template argument 1 is
 invalid
C:/gtkmm/include/gtkmm-2.4/gtkmm/statusicon.h:589: error: template argument 1 is
 invalid
C:/gtkmm/include/gtkmm-2.4/gtkmm/statusicon.h:589: error: ISO C++ forbids declar
ation of `property_gicon' with no type
C:/gtkmm/include/gtkmm-2.4/gtkmm/statusicon.h:599: error: `Gio' has not been dec
lared
C:/gtkmm/include/gtkmm-2.4/gtkmm/statusicon.h:599: error: `Icon' was not declare
d in this scope
C:/gtkmm/include/gtkmm-2.4/gtkmm/statusicon.h:599: error: template argument 1 is
 invalid
C:/gtkmm/include/gtkmm-2.4/gtkmm/statusicon.h:599: error: template argument 1 is
 invalid
C:/gtkmm/include/gtkmm-2.4/gtkmm/statusicon.h:599: error: ISO C++ forbids declar
ation of `property_gicon' with no type

顺便说一句,我也在用``,看起来像:

g++ base.cc -o base `-mms-bitfields -IC:/gtkmm/include/gtkmm-2.4 -IC:/gtkmm/lib/gtkmm-2.4/include -IC:/gtkmm/include/giomm-2.4-IC:/gtkmm/lib/giomm-2.4/include -IC:/gtkmm/include/pangomm-1.4 -IC:/gtkmm/lib/pangomm-1.4/include -IC:/gtkmm/include/gtk-2.0 -IC:/gtkmm/include/atkmm-1.6 -IC:/gtkmm/include/gdkmm-2.4 -IC:/gtkmm/lib/gdkmm-2.4/include -IC:/gtkmm/include/glibmm-2.4 -IC:/gtkmm/lib/glibmm-2.4/include -IC:/gtkmm/include/glib-2.0 -IC:/gtkmm/lib/glib-2.0/include -IC:/gtkmm/include/sigc++-2.0 -IC:/gtkmm/lib/sigc++-2.0/include -IC:/gtkmm/include/cairomm-1.0 -IC:/gtkmm/lib/cairomm-1.0/include -IC:/gtkmm/include/pango-1.0 -IC:/gtkmm/include/cairo -IC:/gtkmm/include/freetype2 -IC:/gtkmm/include -IC:/gtkmm/include/libpng14 -IC:/gtkmm/lib/gtk-2.0/include -IC:/gtkmm/include/atk-1.0  -LC:/gtkmm/lib -lgtkmm-2.4 -latkmm-1.6 -lgdkmm-2.4 -lgiomm-2.4 -lpangomm-1.4 -lgtk-win32-2.0 -lglibmm-2.4 -lcairomm-1.0 -lsigc-2.0 -lgdk-win32-2.0 -latk-1.0 -lgio-2.0 -lgdk_pixbuf-2.0 -lpangowin32-1.0 -lgdi32 -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0-lgthread-2.0 -lglib-2.0 -lintl`

如果我使用 MSYS,我可以编译 base.cc,但我需要在没有 MSYS 的情况下编译它。 关于 PATH 的另一个信息(可能是必要的)(可能这里是错误的):

路径 1:

变量名:路径 变量值:C:\MinGW\bin

路径 2:

变量名:PKG_CONFIG_PATH 变量值:C:\gtkmm\lib\pkgconfig 我能做些什么? 请帮我解决我的问题。 对于我的英语水平,我深表歉意(以防您没有正确理解我的信息)。

【问题讨论】:

【参考方案1】:

根据您的命令行,我猜pkg-config 将输出一组库和编译标志。如果你能确定你的机器的输出是什么,你可以简单地用那个输出代替命令。

我在使用 SDL 时做过类似的事情。它提供了一个sdl-config 脚本,该脚本在我的机器上具有可预测的输出。

【讨论】:

【参考方案2】:

是的,这是可能的。首先,Windows 命令提示符不适用于反抽动。

因此以下命令或类似命令不起作用。

g++ simple.cc -o simple `pkg-config gtkmm-2.4 --cflags --libs`

解决方法是在命令行运行pkg-config gtkmm-2.4 --cflags --libs,将输出复制粘贴到g++ base.cc -o base的末尾。

您发布的以下代码最接近正确。在我看来,这个命令应该可以工作。

g++ base.cc -o base -mms-bitfields -IC:/gtkmm/include/gtkmm-2.4 -IC:/gtkmm/lib/gtkmm-2.4/include -IC:/gtkmm/include/giomm-2.4-IC:/gtkmm/lib/giomm-2.4/include -IC:/gtkmm/include/pangomm-1.4 -IC:/gtkmm/lib/pangomm-1.4/include -IC:/gtkmm/include/gtk-2.0 -IC:/gtkmm/include/atkmm-1.6 -IC:/gtkmm/include/gdkmm-2.4 -IC:/gtkmm/lib/gdkmm-2.4/include -IC:/gtkmm/include/glibmm-2.4 -IC:/gtkmm/lib/glibmm-2.4/include -IC:/gtkmm/include/glib-2.0 -IC:/gtkmm/lib/glib-2.0/include -IC:/gtkmm/include/sigc++-2.0 -IC:/gtkmm/lib/sigc++-2.0/include -IC:/gtkmm/include/cairomm-1.0 -IC:/gtkmm/lib/cairomm-1.0/include -IC:/gtkmm/include/pango-1.0 -IC:/gtkmm/include/cairo -IC:/gtkmm/include/freetype2 -IC:/gtkmm/include -IC:/gtkmm/include/libpng14 -IC:/gtkmm/lib/gtk-2.0/include -IC:/gtkmm/include/atk-1.0  -LC:/gtkmm/lib -lgtkmm-2.4 -latkmm-1.6 -lgdkmm-2.4 -lgiomm-2.4 -lpangomm-1.4 -lgtk-win32-2.0 -lglibmm-2.4 -lcairomm-1.0 -lsigc-2.0 -lgdk-win32-2.0 -latk-1.0 -lgio-2.0 -lgdk_pixbuf-2.0 -lpangowin32-1.0 -lgdi32 -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0-lgthread-2.0 -lglib-2.0 -lintl

只要您在这些目录路径上安装了实用程序,环境变量路径就应该是正确的。

【讨论】:

如果您熟悉 Eclipse 或允许使用 IDE 作为答案,现在 Eclipse CDT 通过插件支持 pkg-config。 marketplace.eclipse.org/content/pkg-config-support-eclipse-cdt/… 欢迎任何反馈!

以上是关于如何在没有 MSYS 的情况下将 gtkmm 与 MinGW (g++) 一起使用?的主要内容,如果未能解决你的问题,请参考以下文章

如何在没有拓扑的情况下将 Windows Media Foundation 与 UWP 结合使用

如何在没有冲突的情况下将 Mocha 和 Jest 与 TypeScript 一起使用?

如何在没有 ObjectId 的情况下将 Mongo 与 Spring Data 一起使用

如何在没有登录页面的情况下将 Keycloak 与 Spring Boot(API) 集成

如何在有和没有 ssh 身份验证的情况下将 Git 与两个不同的存储库一起使用?

SwiftUI:如何在这种情况下将 .overlay 与 GeometryReader 一起使用?