简体   繁体   English

如何在 Windows 上安装 GTK+ 3.0?

[英]How do you install GTK+ 3.0 on Windows?

Trying to setup GTK+ 3.0 on Codeblocks Win7.尝试在 Codeblocks Win7 上设置 GTK+ 3.0。 Having some trouble finding exactly how to do this.很难找到确切的方法。

The GTK website directs you to msys2. GTK 网站将您引导至 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 站点上直接下载了不再存在的多合一 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.就不必要和愚蠢地做一些应该简单的事情而言,它似乎非常linuxy。 Maybe im missing something but should it not be as simple as downloading a zipped folder, extracting and setting up paths?也许我遗漏了一些东西,但它不应该像下载压缩文件夹、提取和设置路径一样简单吗?

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.问题在标题中,我很惊讶我不得不问这个问题,似乎谷歌应该完全涵盖这个问题,但我发现的所有内容都与 GTK 网站上不再提供的下载有关。 I can find no info regarding msys2 and GTK+ 3.0.我找不到有关 msys2 和 GTK+ 3.0 的信息。

Thanks in advance.提前致谢。

Welcome, Google users from the future!欢迎来自未来的 Google 用户! Since I wrote this answer, the GTK+ website now has official installation instructions that cover what I said below but with more details and less pain.自从我写了这个答案,GTK+ 网站现在有官方安装说明,涵盖了我在下面所说的内容,但有更多的细节和更少的痛苦。 Refer to that page instead.请参阅该页面。 The answer below has been kept for historical reasons.由于历史原因,以下答案已被保留。

The problem with the GTK+ website is that there is no one to maintain these binary distributions. GTK+ 网站的问题在于没有人维护这些二进制发行版。 The previous binary distribution for Windows was for GTK+ 3.6, which was released I believe way back in 2012, if not earlier.以前的 Windows 二进制发行版是针对 GTK+ 3.6,我相信它是在 2012 年发布的,如果不是更早的话。 The current version is 3.16, and 3.18 is literally days away from being released.当前版本是 3.16,而 3.18 距离发布还有几天的时间 MSYS2 is the only supported installation mechanism, and it's updated frequently enough. MSYS2 是唯一受支持的安装机制,并且它的更新频率足够高。

That being said, you need to install GTK+ separately if you use the MSYS route;话虽如此,如果您使用 MSYS 路由,则需要单独安装 GTK+; MSYS doesn't come with GTK+ out of the box. MSYS 没有随附开箱即用的 GTK+。 Start with从...开始

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.这应该会为您提供可能要安装的软件包列表,包括适用于 32 位和 64 位 MinGW 的 GTK+ 库。 I forget their exact names now.我现在忘记了他们的确切名字。

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.如果您想要一个用于 GTK+ 编程的传统 IDE,请查找 GNOME Builder 或 Anjuta。 For a graphical GUI designer, look up Glade.对于图形 GUI 设计师,请查找 Glade。

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.有人很友好地将 GTK 文件上传到 Dropbox,只需下载并解压缩即可。 Here is the link for anyone else who bumps into this GTK/msys2 disaster.这是其他遇到此 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。

I agree GNOME community is being a bit insolent to this point.我同意 GNOME 社区在这一点上有点傲慢。 They made GTK+ installation almost the same as the Linux installation, which is a bit like giving you pepsi in mcdonalds.他们使 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.不要使用 code::block 的 GTK+ 项目,它已经过时了。 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)你当然可以修改脚本或创建自己的脚本,但它仍然会减慢你的速度,我们程序员很珍惜我们的时间(我认为)

The procedure of installing (to this day) GTK3 ver.安装(至今)GTK3 版本的过程。 3.22.16 on windows 7 for use with Code::Blocks turns out to be pretty simple. 3.22.16 在 Windows 7 上与 Code::Blocks 一起使用变得非常简单。 First download MSYS2 and type within the msys2 shell:首先下载MSYS2并在 msys2 shell 中输入:

pacman -S mingw-w64-x86_64-gtk3

(Enter y to 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.然后你在 CodeBlocks 中有一些工作,首先设置新的编译器,从 Codeblocks 的编译器设置 -> 工具链可执行文件。 The new compiler should be located in C:\\msys64\\mingw64 (C or the disk you installed MSYS in)新编译器应位于C:\\msys64\\mingw64 (C 或您安装 MSYS 的磁盘)

Then link some libraries in Codeblocks's compiler settings -> Search directories:然后在 Codeblocks 的编译器设置 -> 搜索目录中链接一些库: 在此处输入图片说明 These libraries will be enough to run this simple sample code:这些库足以运行这个简单的示例代码:

#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:并有这样的结果: 在此处输入图片说明

Days ago i send a email to one of the maintainer of gtk for help with vs 2017, and here is the letter.几天前,我向 gtk 的一位维护者发送了一封电子邮件,以寻求有关 vs 2017 的帮助,这是这封信。 After this , i chose to use gtk 2.0 on windows此后,我选择在 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\\include So , I'm wondering if I can directly include those file under msys64 to vs 2017 .我安装了msys2 ,我注意到,在这个文件夹下有许多头并祝.\\msys64\\mingw64\\include所以,我想知道如果我可以直接包括在那些文件msys64到VS 2017 And let vs 2017 to use lib under the folder.like this......并让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.h that you are using matches the glibcocnfig.h.win32 in the source tarball of the version of GLib you are using, because everything that is built against GLib will be affected by it.首先,我不建议使用MSYS版本,除非你确信-你不尝试使用文件结构在你的代码与GLib中使用的那些等-The glibconfig.h您正在使用的匹配glibcocnfig.h.win32在您使用的 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) gtk-3.0.lib(或gtk-3.lib)

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

gdk_pixbuf-2.0.lib gdk_pixbuf-2.0.lib

pangocairo-1.0.lib pangocairo-1.0.lib

pango-1.0.lib pango-1.0.lib

atk-1.0.lib atk-1.0.lib

gio-2.0.lib gio-2.0.lib

gobject-2.0.lib gobject-2.0.lib

gmodule-2.0.lib gmodule-2.0.lib

glib-2.0.lib glib-2.0.lib

cairo-gobject.lib cairo-gobject.lib

cairo.lib cairo.lib

intl.lib内部库

and possibly fontconfig.lib and 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))之前%(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.x to avoid all those trouble.嗯...我花了几天时间将我的程序移植到 Windows,在与gtk 3.x斗争之后,我发现您可以使用gtk 2.x来避免所有这些麻烦。 These are some old file called All-in-one bundle although 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 bundle for gtk 2.x for example这些是一些名为All-in-one bundle旧文件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

If you're looking for projects who, apart from Msys2, provide up-to-date, MSVC-compatible GTK3 stuff, you should check-out gvsbuild and Microsoft's vcpkg .如果您正在寻找除 Msys2 之外还提供最新的、与 MSVC 兼容的 GTK3 内容的项目,您应该查看gvsbuild和 Microsoft 的vcpkg Under the hood, the former uses python and the later uses cmake.在幕后,前者使用 python,后者使用 cmake。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM