C语言 如何在 Windows 上安装 GTK+ 3.0?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32662215/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 12:08:12  来源:igfitidea点击:

How do you install GTK+ 3.0 on Windows?

cwindowsgtkcodeblocksgtk3

提问by NOP da CALL

Trying to setup GTK+ 3.0 on Codeblocks Win7. Having some trouble finding exactly how to do this.

尝试在 Codeblocks Win7 上设置 GTK+ 3.0。很难找到确切的方法。

The GTK website directs you to msys2. It seems there was once a direct download on the GTK site for an all-in-one Windows bundle that is no longer there.

GTK 网站将您引导至 msys2。似乎曾经在 GTK 站点上直接下载了不再存在的多合一 Windows 包。

Having followed the instructions, installed and updated msys2, I see no reference to GTK+, in the installed files or on the mysys website that GTK directs you to.

按照说明安装和更新 msys2 后,我在安装的文件或 GTK 引导您访问的 mysys 网站上看不到对 GTK+ 的引用。

Its seems very linuxy in terms of being unnecessarily and stupidly unclear to do something that should be simple. Maybe im missing something but should it not be as simple as downloading a zipped folder, extracting and setting up paths?

就不必要和愚蠢地做一些应该简单的事情而言,它似乎非常linuxy。也许我遗漏了一些东西,但它不应该像下载压缩文件夹、提取和设置路径一样简单吗?

At this rate id be faster learning C++ and going with Qt.

按照这个速度,我可以更快地学习 C++ 并使用 Qt。

The question is in the title, I am amazed I am having to ask the question, it seems like one that google should have completely covered but everything I am finding is relating to a download that is no longer available on the GTK website. I can find no info regarding msys2 and GTK+ 3.0.

问题在标题中,我很惊讶我不得不问这个问题,似乎谷歌应该完全涵盖这个问题,但我发现的所有内容都与 GTK 网站上不再提供的下载有关。我找不到有关 msys2 和 GTK+ 3.0 的信息。

Thanks in advance.

提前致谢。

回答by andlabs

Welcome, Google users from the future! Since I wrote this answer, the GTK+ website now has official installation instructionsthat cover what I said below but with more details and less pain. Refer to that page instead. The answer below has been kept for historical reasons.

欢迎来自未来的 Google 用户!自从我写了这个答案,GTK+ 网站现在有官方安装说明,涵盖了我在下面所说的内容,但有更多的细节和更少的痛苦。请参阅该页面。由于历史原因,以下答案已被保留。

The problem with the GTK+ website is that there is no one to maintain these binary distributions. The previous binary distribution for Windows was for GTK+ 3.6, which was released I believe way back in 2012, if not earlier. The current version is 3.16, and 3.18 is literally daysaway from being released. MSYS2 is the only supported installation mechanism, and it's updated frequently enough.

GTK+ 网站的问题在于没有人维护这些二进制发行版。以前的 Windows 二进制发行版是针对 GTK+ 3.6 的,我相信它是在 2012 年发布的,如果不是更早的话。当前版本是 3.16,而 3.18距离发布还有几天的时间。MSYS2 是唯一受支持的安装机制,并且它的更新频率足够高。

That being said, you need to install GTK+ separately if you use the MSYS route; MSYS doesn't come with GTK+ out of the box. Start with

话虽如此,如果您使用 MSYS 路由,则需要单独安装 GTK+;MSYS 没有随附开箱即用的 GTK+。从...开始

pacman -Ss gtk3

That should give you a list of possible packages to install, including the GTK+ libraries for both 32-bit and 64-bit MinGW. I forget their exact names now.

这应该会为您提供可能要安装的软件包列表,包括适用于 32 位和 64 位 MinGW 的 GTK+ 库。我现在忘记了他们的确切名字。

Once you find the one you want, use

一旦你找到你想要的,使用

pacman -S package-name-here

to install it. Then, open the MinGW 32-bit or 64-bit Shell from the Start menu's MSYS folder to begin developing.

安装它。然后,从开始菜单的 MSYS 文件夹中打开 MinGW 32 位或 64 位 Shell 以开始开发。

If you want a traditional IDE for GTK+ programming, look up GNOME Builder or Anjuta. For a graphical GUI designer, look up Glade.

如果您想要一个用于 GTK+ 编程的传统 IDE,请查找 GNOME Builder 或 Anjuta。对于图形 GUI 设计师,请查找 Glade。

回答by NOP da CALL

Hallelujah, I have found the sane non linux version of getting GTK for windows.

哈利路亚,我找到了为 Windows 获取 GTK 的非 linux 版本。

Someone was kind enough to upload to dropbox the GTK files, just download and extract. Here is the link for anyone else who bumps into this GTK/msys2 disaster.

有人很友好地将 GTK 文件上传到 Dropbox,只需下载并解压缩即可。这是其他遇到此 GTK/msys2 灾难的人的链接。

https://www.dropbox.com/sh/8d1qbh5dsp044on/UgkALzhlqH

https://www.dropbox.com/sh/8d1qbh5dsp044on/UgkALzhlqH

These files really ought to be available on the GTK Windows download page, it beggars belief.

这些文件真的应该可以在 GTK Windows 下载页面上找到,它令人难以置信。

Close this thread, viva windows.

关闭此线程,viva windows。

回答by Edenia

I agree GNOME community is being a bit insolent to this point. They made GTK+ installation almost the same as the Linux installation, which is a bit like giving you pepsi in mcdonalds.

我同意 GNOME 社区在这一点上有点傲慢。他们使 GTK+ 安装几乎与 Linux 安装相同,这有点像在麦当劳给你百事可乐。

The worst is that it is forcing you to use their own crap to the extent that they even tell you what IDE to choose, how you will build your app, what will have in your app.. (Nothing personal, I will actually always prefer Linux, I'm just being unbiased)

最糟糕的是,它迫使你使用他们自己的废话,以至于他们甚至会告诉你选择什么 IDE,你将如何构建你的应用程序,你的应用程序中会有什么......(没什么私人的,我实际上总是更喜欢Linux,我只是不偏不倚)



Now to be specific, you explicitly mentioned Codeblocks. Do not use code::block's GTK+ Project, it is awfully outdated. You can, of course modify the script or create your own, but it is still going to slow you down and we, programmers value our time (I think)

现在具体来说,您明确提到了代码块。不要使用 code::block 的 GTK+ 项目,它已经过时了。你当然可以修改脚本或创建自己的脚本,但它仍然会减慢你的速度,我们程序员很珍惜我们的时间(我认为)

The procedure of installing (to this day) GTK3 ver. 3.22.16 on windows 7 for use with Code::Blocks turns out to be pretty simple. First download MSYS2and type within the msys2 shell:

安装(至今)GTK3 版本的过程。3.22.16 在 Windows 7 上与 Code::Blocks 一起使用变得非常简单。首先下载MSYS2并在 msys2 shell 中输入:

pacman -S mingw-w64-x86_64-gtk3

pacman -S mingw-w64-x86_64-gtk3

(Enter yto confirm) Then

(回车y确认)然后

pacman -S mingw-w64-x86_64-toolchain base-devel(to make sure you'll have precompiled binaries of pkg-config and to make sure you will have the latest version of gcc)

pacman -S mingw-w64-x86_64-toolchain base-devel(以确保您将拥有 pkg​​-config 的预编译二进制文件并确保您将拥有最新版本的 gcc)

Then you have some work in CodeBlocks, first set the new compiler, from the Codeblocks's compiler settings -> Toolchain executables. The new compiler should be located in C:\msys64\mingw64(C or the disk you installed MSYS in)

然后你在 CodeBlocks 中有一些工作,首先设置新的编译器,从 Codeblocks 的编译器设置 -> 工具链可执行文件。新编译器应位于C:\msys64\mingw64(C 或您安装 MSYS 的磁盘中)

Then link some libraries in Codeblocks's compiler settings -> Search directories: enter image description hereThese libraries will be enough to run this simple sample code:

然后在 Codeblocks 的编译器设置 -> 搜索目录中链接一些库: enter image description here这些库足以运行这个简单的示例代码:

#include <gtk/gtk.h>

static void activate (GtkApplication* app, gpointer user_data)
{
    GtkWidget *window;

    window = gtk_application_window_new(app);
    gtk_window_set_title(GTK_WINDOW (window), "Window");
    gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
    gtk_widget_show_all(window);
}

int main (int argc, char *argv[])
{
    GtkApplication *app;
    int status;

    app     = gtk_application_new("org.gtk.example", G_APPLICATION_FLAGS_NONE);
    g_signal_connect(app, "activate", G_CALLBACK (activate), NULL);
    status  = g_application_run(G_APPLICATION (app), argc, argv);
    g_object_unref(app);

    return status;
}

and have a result like this:enter image description here

并有这样的结果:enter image description here

回答by Z-Y00

Days ago i send a email to one of the maintainer of gtk for help with vs 2017, and here is the letter. After this , i chose to use gtk 2.0 on windows

几天前,我向 gtk 的一位维护者发送了一封电子邮件,以寻求有关 vs 2017 的帮助,这是这封信。此后,我选择在 windows 上使用 gtk 2.0

This is mine

这是我的

I installed the msys2, and I noticed that , there are many head fille under this folder .\msys64\mingw64\includeSo , I'm wondering if I can directly include those file under msys64to vs 2017. And let vs 2017 to use lib under the folder.like this......

我安装了msys2,我注意到,这个文件夹下有很多头文件.\msys64\mingw64\include所以,我想知道我是否可以直接将这些文件包含在msys64vs 下2017。并让vs 2017使用文件夹下的lib。像这样......

and this is from him

这是他的

First off, I do not recommend using the msys builds, unless you are sure that -You do not attempt to use FILE structures in your code with the ones used by GLib, etc. -The glibconfig.hthat you are using matches the glibcocnfig.h.win32in the source tarball of the version of GLib you are using, because everything that is built against GLib will be affected by it.

首先,我不建议使用 msys 构建,除非您确定 - 您不会尝试在代码中使用 FILE 结构和 GLib 等使用的结构。 -glibconfig.h您使用的与glibcocnfig.h.win32源 tarball 中的匹配您正在使用的 GLib 版本,因为针对 GLib 构建的所有内容都会受到它的影响。

If you still decide to go down this route, you need to specify the libraries when you link. See Linker->Input->Additional Dependencies, you will need at least the following .lib files, separated by semicolons:

如果您仍然决定沿着这条路线走,则需要在链接时指定库。看Linker->Input->Additional Dependencies,您至少需要以下内容.lib files,以分号分隔:

gtk-3.0.lib (or gtk-3.lib)

gdk-3.0.lib (or gdk-3.lib)

gdk_pixbuf-2.0.lib

pangocairo-1.0.lib

pango-1.0.lib

atk-1.0.lib

gio-2.0.lib

gobject-2.0.lib

gmodule-2.0.lib

glib-2.0.lib

cairo-gobject.lib

cairo.lib

intl.lib

gtk-3.0.lib(或gtk-3.lib)

gdk-3.0.lib(或 gdk-3.lib)

gdk_pixbuf-2.0.lib

pangocairo-1.0.lib

pango-1.0.lib

atk-1.0.lib

gio-2.0.lib

gobject-2.0.lib

gmodule-2.0.lib

glib-2.0.lib

cairo-gobject.lib

cairo.lib

内部库

and possibly fontconfig.liband freetype.lib, as probably the msys64 builds include support for them.

并且可能fontconfig.libfreetype.lib,因为可能 msys64 构建包括对它们的支持。

You will also need to link to any other libraries that you may use for your assignment. Prepend these libraries with a trailing ;before %(AdditionalDependencies) (don't remove %(AdditionalDependencies))

您还需要链接到您可能用于作业的任何其他库。在这些库;之前 加上尾随%(AdditionalDependencies) (don't remove %(AdditionalDependencies))

With blessings, and cheers!

带着祝福和欢呼!

Well...i've spend several days to port my program to windows, after struggle with gtk 3.x, i found that you may use gtk 2.xto avoid all those trouble. These are some old file called All-in-one bundlealthough it is important to know that , there is some security issue with it,(plus you need to rewrite it to gtk 2.0) but if you are mainly using linux ,and just wanna it to run on windows , i'll suggest you to use old All-in-one bundlefor gtk 2.x for example

嗯......我花几天的时间来港我的程序窗口,有斗争后gtk 3.x,我发现,您可以使用gtk 2.x,以避免所有这些麻烦。这些是一些旧文件,All-in-one bundle尽管知道这一点很重要,但它存在一些安全问题(另外您需要将其重写为 gtk 2.0)但如果您主要使用 linux,并且只想让它在 Windows 上运行,例如,我建议您将旧的All-in-one bundle用于 gtk 2.x

https://download.gnome.org/binaries/win32/gtk+/2.24/gtk+-bundle_2.24.10-20120208_win32.zip.mirrorlist

https://download.gnome.org/binaries/win32/gtk+/2.24/gtk+-bundle_2.24.10-20120208_win32.zip.mirrorlist

回答by sgeto

If you're looking for projects who, apart from Msys2, provide up-to-date, MSVC-compatible GTK3 stuff, you should check-out gvsbuildand Microsoft's vcpkg. Under the hood, the former uses python and the later uses cmake.

如果您正在寻找除 Msys2 之外还提供最新的、与 MSVC 兼容的 GTK3 内容的项目,您应该查看gvsbuild和 Microsoft 的vcpkg。在幕后,前者使用 python,后者使用 cmake。