How do you install GTK+ 3.0 on Windows?
Solution 1
Welcome, Google users from the future! 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. 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. 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 days away from being released. MSYS2 is the only supported installation mechanism, and it's updated frequently enough.
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
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.
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.
If you want a traditional IDE for GTK+ programming, look up GNOME Builder or Anjuta. For a graphical GUI designer, look up Glade.
Solution 2
Hallelujah, I have found the sane non linux version of getting GTK for windows.
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.
https://www.dropbox.com/sh/8d1qbh5dsp044on/UgkALzhlqH
These files really ought to be available on the GTK Windows download page, it beggars belief.
Close this thread, viva windows.
Solution 3
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.
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)
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)
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 MSYS2 and type within the msys2 shell:
pacman -S mingw-w64-x86_64-gtk3
(Enter y
to confirm)
Then
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)
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)
Then link some libraries in Codeblocks's compiler settings -> Search directories: 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;
}
Solution 4
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
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
. And let vs
2017 to use lib under the folder.like this......
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.
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:
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
and possibly fontconfig.lib
and freetype.lib
, as probably the msys64
builds include support for them.
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))
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. 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
Solution 5
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. Under the hood, the former uses python and the later uses cmake.
NOP da CALL
Updated on April 06, 2020Comments
-
NOP da CALL about 4 years
Trying to setup GTK+ 3.0 on Codeblocks Win7. Having some trouble finding exactly how to do this.
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.
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.
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?
At this rate id be faster learning C++ and going with 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.
Thanks in advance.
-
NOP da CALL over 8 yearsExcellent, I knew it would be something simple for people who know linux. I actually managed to find the windows 3.6.4 download here win32builder.gnome.org/gtk+-bundle_3.6.4-20130921_win32.zip and it seems to be working so far without going through the msys2 way you have shown. How is a windows user supposed to know to do that btw, the windows GTK page should certainly be updated with more clear instructions? If I have any problems I will try reinstall with the method you have given but hopefully I dont have to. Thanks for the recommendations, I was planning on checking Glade out.
-
liberforce over 8 yearsActually, that's exactly what GTK people didn't want to deliver, so that people that develop using GTK and want to distribute their apps know what they need.
-
Freddy Pierson about 8 yearsExcuse my ignorance, but why has this post been downvoted? Isn't it a good thing that GTK binaries for Windows now exist?
-
Fabio Zadrozny about 8 yearsWell, not sure why it was downvoted too, but I really wish it came from a source with more authority than a dropbox link...
-
Wesley over 7 years@FabioZadrozny Sorry, I'm late. I believe this is the original post. stackoverflow.com/a/22522417/2403756
-
NOP da CALL almost 7 yearsThank you for the answer but I finally managed to not break Linux and have been using it exclusively for a while now. Viva Linux, Viva Python
-
Edenia almost 7 years@NOPdaCALL You are doing great. Considering that this is more like a linux project ported to Windows additionally.
-
Edenia almost 7 yearsAlso I suspected you've managed to handle it correctly. There are still people wondering how to easily install it on windows though. The newest versions are very different, more compact, better structured and pretty improved.
-
Lothar over 6 yearsThanks, but i have to say this is pretty common task. If you don't know how to add a bunch of lib files to your project and know that you should not pass FILE and other structures across API boundaries (DLL files - not necessary now anymore with the universal c runtime) then you have to learn the basics of C programming on windows again.
-
Y00 over 6 years@Lothar sorry, i've never learned any thing about programming on windows. I thought that this msys2 build is suitable for direct usage , and solved all the API issue.
-
Y00 over 6 years@Lothar by the way , the GTK 2.0 provided support for Windows , and as far as i know , can pass FILE and other structures across API boundaries. Sorry to bother you , because i do not know any thing about programming on windows, i know this is stupid for your guys.
-
liberforce over 6 yearsIt's downvoted because getting stuff from an untrusted random location on the web is dumb. That's why the GTK+ team points to the MSYS2 project. If GTK+ trusts MSYS2, and you trust GTK+, then you should trust MSYS2.
-
liberforce over 6 yearsDon't use bundles, they're all out of date. Use MSYS2 as that's what GTK+ developers say that's what is supported on Windows. I rewrote the installation instructions since that answer was written. You should now be able to install GTK+ using MSYS2 with no pain following the official instructions: gtk.org/download/windows.php
-
andlabs over 6 years@liberforce Excellent! I've updated the answer with this new information.
-
liberforce over 6 yearsYou said:
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.
. GTK+ is an open source project and everyone is welcome to contribute. But if Windows developers don't, then there's nobody to do the job and the GNOME developers will do what is easier for their limited resources. Switching the build system to the Meson build system will hopefully make GTK+ 4 easier to integrate on Windows. -
Cool Javelin over 5 yearsSo, How would I use the GTK+ toolkit WITHOUT installing yet another down loader and IDE using up 450MB on my disk? Also, I already have minGW on my disk, do I really need ANOTHER copy? I want to use Code::Blocks, or eclipse, or Net beans, all of which I already have on my computer. I understand the philosophy behind the down loader, it delivers the latest and greatest, but in practice it's just a bad idea. My computer is getting so polluted with down loaders, compilers, IDE's it makes my head spin. I just want to produce something that will make me money, not spend a day learning something new
-
Admin over 4 yearsI followed the instructions, but when I try to build my project with CMake, I get the following error: "No package 'gtk+-3.0' found". What can be the problem and how can I fix this?
-
am70 about 2 yearsjust my 2 cents: instead of installing MSYS2 and pretending you have a a somewhat linux environment in Windows, I would install WSL and then install a true linux distribution inside it. This both for developers and for end users,