How to build a GTK+3 program on Windows without MSYS2?

偶尔善良 提交于 2020-05-15 02:52:58

问题


I want to compile a code in GTK+3. Without using MSYS2 nor Visual Studio. I'm getting "undefined reference to"

First, tried with this tutorial from the official page: https://www.gtk.org/download/windows.php but it was a mess using MSYS2; plus, i dont want a linux like nor a unix like environment (a lot less Visual Studio).

I downloaded the "all in one bundle" for version 2, setted up the enviroment variable an all that stuff. Everything worked fine, the code compiled! (a code from version 2). Then i tried to change to version 3, downloaded the all in one bundle (64 bits) from: http://www.tarnyko.net/dl/gtk.htm

Of course, the enviroment variable was updated, and the verions of the libraries in the compiling line too. And the program is for version 3, specifically the first in the official site: https://developer.gnome.org/gtk3/stable/gtk-getting-started.html. Didn't worked.

Then, followed this tutorial: http://www.tarnyko.net/repo/gtk3_build_system/tutorial/gtk3_tutorial.htm

I rewroted the compiling line with the result of the command: pkg-config --cflags --libs gtk+-3.0 (as the tutorial above says)

the compilation line for the version 2 (works right) is:

gcc -Wall -g test.c -o test -mms-bitfields -Ic:/gtk/include/gtk-2.0 -Ic:/gtk/lib/gtk-2.0/include -Ic:/gtk/include/atk-1.0 -Ic:/gtk/include/cairo -Ic:/gtk/include/gdk-pixbuf-2.0 -Ic:/gtk/include/pango-1.0 -Ic:/gtk/include/glib-2.0 -Ic:/gtk/lib/glib-2.0/include -Ic:/gtk/include -Ic:/gtk/include/freetype2 -Ic:/gtk/include/libpng14 -Lc:/gtk/lib -lgtk-win32-2.0 -lgdk-win32-2.0 -latk-1.0 -lgio-2.0 -lpangowin32-1.0 -lgdi32 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lglib-2.0 -lintl

the compiling line for version 3 (the one i'm asking) is:

gcc -Wall -g iniciando.c -o iniciando -mms-bitfields -IC:/gtk3/include/gtk-3.0 -IC:/gtk3/include/cairo -IC:/gtk3/include/pango-1.0 -IC:/gtk3/include/atk-1.0 -IC:/gtk3/include/cairo -IC:/gtk3/include/pixman-1 -IC:/gtk3/include -IC:/gtk3/include/freetype2 -IC:/gtk3/include -IC:/gtk3/include/libpng15 -IC:/gtk3/include/gdk-pixbuf-2.0 -IC:/gtk3/include/libpng15 -IC:/gtk3/include/glib-2.0 -IC:/gtk3/lib/glib-2.0/include -LC:/gtk3/lib -lgtk-3 -lgdk-3 -lgdi32 -limm32 -lshell32 -lole32 -Wl,-luuid -lpangocairo-1.0 -lpangoft2-1.0 -lfreetype -lfontconfig -lpangowin32-1.0 -lgdi32 -lpango-1.0 -lm -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lintl

The last lib (intl), at the begining gave problems because it didn't exist where it's suppose to be, and nothing compiled; i removed it and got the error i'm asking for, then copied the intl from my GTK 2 (just to see what happened), the error is the same.

I expect the program to be compiled; but I am getting: undefined reference to: 'gtk_main_quit' (and all GTK functions).


回答1:


First, forget about using GTK+ 2, it's going to be deprecated once GTK+ 4 is released (probably this summer). Use GTK+ 3, which has been stable for years.

Second, forget everything about the instructions found on Tarniko's website. While he did a great job at the time, these instructions are now completely outdated, and the precompiled binaries are for outdated versions of GTK+ (3.6 was released in september 2012, while latest release is 3.24 released in september 2018)

There is no official precompiled binaries other than those provided by MSYS or the vcpkg packages. You may find some more up to date and unofficial bundles, like this one (never tried it), but getting binaries from an untrusted source may be a security issue.

Next, you need a toolchain if you actually want to build something. You seem to already have gcc installed, how did you install it? If you want to use precompiled binaries, you will have to install and configure the toolchain by yourself as this is specific to your setup. Usually to avoid compatibility problems, you want the same toolchain that was used to build your dependencies, and that's what MSYS provides.

In last resort, you might just build the whole thing from source, as recent GTK+ versions can be built using the Meson build system which should build fine on Windows.

But really, if you already plan to use gcc, just do yourself a favor and install MSYS2. You'll get GTK+, a toolchain, as well as bindings, and other tools like glade and devhelp, which (at least for Glade) will probably need if you want to do some serious GTK+ development.



来源:https://stackoverflow.com/questions/56784001/how-to-build-a-gtk3-program-on-windows-without-msys2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!