我需要将GTK+应用程序从GNU/Linux(Arch Linux)交叉编译到Windows。我已经尝试使用mingw32
,但它无法看到所有库(包括C的标准库!)。所以,我需要找到标准库;找到所有其他库(glib、gio、gtk等)。但是有一个问题-我无法找到它们。我也无法从Windows编译。我该怎么办?
我需要将GTK+应用程序从GNU/Linux(Arch Linux)交叉编译到Windows。我已经尝试使用mingw32
,但它无法看到所有库(包括C的标准库!)。所以,我需要找到标准库;找到所有其他库(glib、gio、gtk等)。但是有一个问题-我无法找到它们。我也无法从Windows编译。我该怎么办?
一旦您提取了它们,您可以按照这个教程进行以下步骤:
1)安装编译工具链
安装Windows的GCC编译器(即MinGW,Arch Linux软件包文档):
#pacman -S migw-w64
直接从官方网站下载最新的全套ZIP压缩包(这是一个直接的链接)
将GTK+适应其位置:在终端中,移动到您刚刚创建的“gtk3-win32”文件夹。例如:$cd /opt/gtk3-win32
然后执行:
find -name '*.pc' | while read pc; do sed -e "s@^prefix=.*@prefix=$PWD@" -i "$pc"; done
2)编译
We will tell pkg-config
to locate GTK+3 libraries in our custom path. If you extracted to /opt/gtk3-win32
:
export PKG_CONFIG_PATH=/opt/gtk3-win32/lib/pkgconfig
We are ready to compile a sample C source ! Let's use a command in this style :
i586-mingw32msvc-gcc source.c -o executable.exe `pkg-config --cflags --libs gtk+-3.0
Create a folder containing the binary and the Windows .dll files. If you extracted to /opt/gtk3-win32
:
mkdir ~/distri
cp executable.exe ~/distri
cp /opt/gtk3-win32/bin/*.dll ~/distri
Here we go ! Transfer this folder to a Windows box. Double-click on the executable and...
pacman -S mingw-w64-i686-gtk3
cd /mingw32
tar cfz c:/temp/mingw32.tar.gz
对于gcc 5.3.0,请编辑/etc/pacman.conf文件。
[core]
Server = https://archive.archlinux.org/repos/2016/05/10/$repo/os/$arch
[extra]
Server = https://archive.archlinux.org/repos/2016/05/10/$repo/os/$arch
[community]
Server = https://archive.archlinux.org/repos/2016/05/10/$repo/os/$arch
pacman -Syu
如果降级的情况发生
pacman -Syyuu
后来的 Arch Linux 版本似乎有 gcc 6.1.1,可能与 msys2 的 gcc 不兼容。对于不进行升级的 Arch Linux 安装(即无安全更新),虚拟机可能是一个好主意。
在 Linux 上解压 mingw32.tar.gz,例如在 /opt/mingw32 中。
perl -pi.bak -e 's,^prefix=.*,prefix=/opt/mingw32,' /opt/mingw32/lib/pkgconfig/*.pc
例如,在执行配置脚本之前
export PKG_CONFIG_PATH=/opt/mingw32/lib/pkgconfig
--disable-dw2-exceptions
构建。 - J.J. Hakala