如何在没有MSYS2的Windows上构建GTK + 3程序? [英] How to build a GTK+3 program on Windows without MSYS2?

查看:434
本文介绍了如何在没有MSYS2的Windows上构建GTK + 3程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用GTK + 3编译代码.不使用MSYS2或Visual Studio. 我收到未定义的引用"

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

首先,从官方页面尝试使用本教程: https://www.gtk. org/download/windows.php ,但是使用MSYS2时一团糟;另外,我不希望有类似Linux的环境,也不想像类似Unix的环境(Visual Studio少得多).

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).

我下载了版本2的所有软件包",为所有环境设置了环境变量.一切正常,代码已编译! (版本2中的代码).然后,我尝试更改为版本3,并从一个捆绑包(64位)中下载了所有文件: http ://www.tarnyko.net/dl/gtk.htm

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

当然,环境变量也已更新,编译行中的库版本也已更新.该程序适用于版本3,尤其是官方网站中的第一个版本: https://developer.gnome.org/gtk3/stable/gtk-getting-started.html .没有工作.

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.

然后,按照本教程操作: http://www.tarnyko.net /repo/gtk3_build_system/tutorial/gtk3_tutorial.htm

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

我用以下命令的结果回退了编译行:pkg-config --cflags --libs gtk+-3.0(如上面的教程所述)

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

版本2的编译行(正确运行)是:

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

第3版(我要问的)的编译行是:

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

最初的最后一个lib(intl)出现了问题,因为它本来就不存在,并且没有进行编译;我删除了它并得到了我要的错误,然后从我的GTK 2中复制了intl(只是看看发生了什么),错误是相同的.

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.

我希望程序会被编译;但我得到了:undefined reference to: 'gtk_main_quit'(以及所有GTK函数).

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

推荐答案

首先,忘记使用GTK + 2,一旦发布GTK + 4(可能是今年夏天),它将不推荐使用.使用已经稳定多年的GTK + 3.

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.

第二,忘记有关Tarniko网站上的说明的所有信息.尽管他当时做得很好,但这些说明现在已经完全过时了,预编译的二进制文件是针对过时的GTK +版本的(3.6已于2012年9月发布,而最新版本是3.24已于2018年9月发布)

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)

除了MSYS或vcpkg软件包提供的二进制文件外,没有官方的预编译二进制文件.您可能会发现更多最新的和非官方的捆绑包,像这样的(从未尝试过),但是从不受信任的来源获取二进制文件可能是一个安全问题.

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.

接下来,如果您确实想构建某些东西,则需要一个工具链.您似乎已经安装了gcc,如何安装它?如果要使用预编译的二进制文件,则必须自行安装和配置工具链,因为这是特定于您的设置的.通常,为了避免兼容性问题,您需要使用与构建依赖关系相同的工具链,而这正是MSYS提供的.

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.

在万不得已的情况下,您可能只是从源头构建整个内容,因为可以使用Meson构建系统构建最新的GTK +版本,该系统应该可以在Windows上很好地构建.

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.

但是,实际上,如果您已经打算使用gcc,请帮帮忙并安装MSYS2.您将获得GTK +,一个工具链,绑定以及诸如glade和devhelp之类的其他工具,如果您想进行认真的GTK +开发,可能(至少对于Glade而言)需要这些工具.

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.

这篇关于如何在没有MSYS2的Windows上构建GTK + 3程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆