为 32 位和 64 位构建 Winelib DLL 的“正确”方法是什么?

问题描述 投票:0回答:1

我目前正在开发一个项目,该项目要求我将 Windows DLL 重新实现为 Wine DLL(Linux 共享对象)。我希望这个 DLL 可用于 32 位和 64 位 Wine 进程,并且我正在 64 位 OpenSUSE Tumbleweed 机器上构建它。

到目前为止,我只能使用

将我的实现编译为 32 位 Winelib DLL
winegcc -m32 -L/usr/lib/wine/i386-unix -shared -o myproject.dll myproject_main.c myproject.spec

指定

-L/usr/lib/wine/i386-unix
是必要的,因为即使
winegcc
也没有获取 Wine 的库路径。
myproject.dll.so
有效:32 位 Wine 进程可以加载该库并毫无问题地使用它。

然后,我尝试使用

将其编译为64位对象
winegcc -L/usr/lib64/wine/x86_64-unix -shared -o myproject64.dll myproject_main.c myproject.spec

但无济于事。链接失败并显示消息

/usr/lib64/gcc/x86_64-suse-linux/14/../../../../x86_64-suse-linux/bin/ld: cannot find -ladvapi32: No such file or directory
/usr/lib64/gcc/x86_64-suse-linux/14/../../../../x86_64-suse-linux/bin/ld: cannot find -luser32: No such file or directory
/usr/lib64/gcc/x86_64-suse-linux/14/../../../../x86_64-suse-linux/bin/ld: cannot find -lwinecrt0: No such file or directory
/usr/lib64/gcc/x86_64-suse-linux/14/../../../../x86_64-suse-linux/bin/ld: cannot find -lkernel32: No such file or directory
/usr/lib64/gcc/x86_64-suse-linux/14/../../../../x86_64-suse-linux/bin/ld: cannot find -lntdll: No such file or directory
collect2: error: ld returned 1 exit status
winegcc: /usr/bin/gcc failed

检查

/usr/lib/wine/i386-unix
/usr/lib64/wine/x86_64-unix
之间的差异后,我发现后者根本不包含必要的存档文件(例如
libkernel32.a
),而前者则包含。我还有一个
/usr/lib64/wine/x86_64-windows
文件夹,其中包含这些存档文件,但它们是 PE 二进制文件,因此不能用于链接。

事实上,OpenSUSE 的软件包不会填充

x86_64-unix
中的存档文件,而仅在构建时填充
x86_64-windows
中。我检查过,Fedora 的软件包(至少是来自 WineHQ 的官方软件包)似乎有相反的问题:我找不到
i386-unix
存档文件,但软件包包含
x86_64-unix
的文件。

我已经在 OpenSUSE 论坛 上询问过这个问题,我被要求去 Wine 论坛询问,因为“这似乎不是打包问题”。我在 WineHQ 论坛 上的帖子尚未得到回复,所以我想知道我的方法是否错误:我觉得我也应该能够将我的实现编译为 64 位二进制文件。如果这就是它应该工作的方式,我将如何编译 64 位二进制文件?

linux 32bit-64bit opensuse wine winelib
1个回答
0
投票

用这种方式编译Winelib DLL确实是正确的。我遇到的问题源于我报告的 openSUSE Wine 软件包的问题。

在这个问题得到解决之前,从源代码构建 Wine 可以解决这个问题。克隆 Wine 存储库后,可以使用

进行编译
./configure --enable-archs=i386,x86_64 --enable-win64 --prefix=/path/to/builddir
make -j 4
make install

请注意,

--prefix=
指定将生成 Wine 可执行文件等的位置,以免覆盖任何系统 Wine。

编译完成后,我们可以使用我们自建的winegcc来编译我们的Winelib DLL,如下所示:

# 32-bit DLL
/path/to/builddir/bin/winegcc -m32 --winebuild /path/to/builddir/bin/winebuild -shared -o myproject.dll myproject_main.c myproject.spec

# 64-bit DLL
/path/to/builddir/bin/winegcc --winebuild /path/to/builddir/bin/winebuild -shared -o myproject.dll myproject_main.c myproject.spec

如果您安装了另一个(系统范围)版本的

--winebuild
,则需要指定
winebuild
。这将确保我们的自建
winegcc
使用我们的自建
winebuild

事实上,为

-L
查找库/归档文件的位置指定
winegcc
是多余的,并且是 openSUSE 软件包中的另一个错误(我也报告过)。

我们自建Wine构建/链接的Winelib DLL与系统Wine版本兼容,只要系统版本比我们自建版本一样旧或新。也就是说,在从源代码构建 Wine 时,请始终克隆/签出您的 DLL 应兼容的最旧的 Wine 版本。

© www.soinside.com 2019 - 2024. All rights reserved.