简体   繁体   English

如何在没有MSYS2的Windows上构建GTK + 3程序?

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

I want to compile a code in GTK+3. 我想在GTK + 3中编译代码。 Without using MSYS2 nor Visual Studio. 不使用MSYS2或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; 首先,在官方页面上尝试使用本教程: https ://www.gtk.org/download/windows.php,但是使用MSYS2时一团糟。 plus, i dont want a linux like nor a unix like environment (a lot less Visual Studio). 另外,我不想要类似Linux的环境,也不希望像类似Unix的环境(Visual Studio少得多)。

I downloaded the "all in one bundle" for version 2, setted up the enviroment variable an all that stuff. 我下载了版本2的“捆绑包”,为所有环境变量设置了环境变量。 Everything worked fine, the code compiled! 一切正常,代码已编译! (a code from version 2). (版本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 然后,我尝试更改为版本3,并从以下网站下载了全部捆绑包(64位): 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 . 该程序适用于版本3,特别是官方网站中的第一个版本: 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 然后,按照本教程进行操作: 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) 我用以下命令的结果重新编译了编译行: pkg-config --cflags --libs gtk+-3.0 (如上面的教程所述)

the compilation line for the version 2 (works right) is: 版本2的编译行(正确运行)是:

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: 版本3(我要求的版本)的编译行是:

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; 最初的最后一个lib(intl)出现了问题,因为它在应该存在的位置不存在,并且没有编译。 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. 我删除了它并得到了我要的错误,然后从我的GTK 2中复制了intl(只是看看发生了什么),错误是相同的。

I expect the program to be compiled; 我希望程序会被编译; but I am getting: undefined reference to: 'gtk_main_quit' (and all GTK functions). 但我得到: undefined reference to: 'gtk_main_quit' (和所有GTK函数)。

First, forget about using GTK+ 2, it's going to be deprecated once GTK+ 4 is released (probably this summer). 首先,忘记使用GTK + 2,一旦发布GTK + 4(可能在今年夏天),它将不推荐使用。 Use GTK+ 3, which has been stable for years. 使用已经稳定多年的GTK + 3。

Second, forget everything about the instructions found on Tarniko's website. 其次,忘记有关Tarniko网站上的说明的所有信息。 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) 尽管他当时做得很好,但这些说明现在已经完全过时了,并且预编译的二进制文件是针对过时的GTK +版本的(3.6已于2012年9月发布,而最新版本是3.24已于2018年9月发布)

There is no official precompiled binaries other than those provided by MSYS or the vcpkg packages. 除了MSYS或vcpkg软件包提供的二进制文件外,没有官方的预编译二进制文件。 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? 您似乎已经安装了gcc,如何安装它? 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. 通常,为了避免兼容性问题,您需要使用与构建依赖关系相同的工具链,这就是MSYS提供的工具链。

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. 在最后的选择中,您可能只是从源代码构建整个事物,因为可以使用Meson构建系统构建最新的GTK +版本,该系统应该可以在Windows上很好地构建。

But really, if you already plan to use gcc, just do yourself a favor and install MSYS2. 但是实际上,如果您已经打算使用gcc,请帮自己一个忙,安装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. 您将获得GTK +,一个工具链以及绑定,以及诸如glade和devhelp之类的其他工具,如果您想进行认真的GTK +开发,可能至少需要(至少对于Glade而言)。

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

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