35
votes

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.

5
for GUI, I am a beginner programmer and only know some C at this stage.NOP da CALL
I would but I quite enjoy being alive right now and having to deal with the never ending headache that is Linux would put that in jeopardy. Respect to people who use Linux but on the few occasions I have given it chance, it has just been one problem after another before I can even attempt to use the computer for what I want to do. I love the Linux open source philosophy but I dont have the knowledge or the heart/desire to obtain the knowledge to replicate my windows setups on it. Windows just works, I use XP/7 and with the tablification of new Windows OS's now I doubt ill ever be leaving them.NOP da CALL
"GTK+ is available on: Windows" - why should I need to learn Linux? If you could link me to "the guide on the GTK+ website telling you exactly how to install the packages on windows using msys2" I would be eternally grateful as I cannot see it.NOP da CALL
Thats what I thought, a page telling you what you need but not how to get it. It tells you absolutely nothing about getting the required packages through msys2, it just point you them and that the end of it. "The preferred way to obtain GTK+ and its dependencies in binary form for Windows is to use the MSYS2 project. You can find more information in this article." went through the full article to install msys2, no mention of GTK as I stated in the OP.NOP da CALL
The only troll here is redFIVE. Ignore him.andlabs

5 Answers

43
votes

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.

12
votes

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.

6
votes

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: enter image description here 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:enter image description here

2
votes

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

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

1
votes

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.