gpt4 book ai didi

windows - libtool 和 Windows DLL

转载 作者:可可西里 更新时间:2023-11-01 13:47:04 27 4
gpt4 key购买 nike

我与 GNU autotools 关系不好,尤其是 libtool。但是因为它们在可移植性和交叉编译方面表现出色,所以我又开始使用它们了。

不幸的是,我无法使用 libtool 来构建合适的 Windows DLL。然而,使用 vanilla make gcc会很乐意为我构建 DLL。

例如:

LIBEXT = .dll

pkzo$(LIBEXT): $(patsubst %.cpp, %.o, $(pkzo_SOURCES)) resources.o
$(CXX) -shared -fPIC $(CXXFLAGS) $^ $(LDFLAGS) -Wl,--out-implib=libpkzo.lib -o $@

将很快构建一个 DLL 并导入库。 (即使没有任何烦人的 decelspec)。

然而,如果我像这样使用 libtool:

lib_LTLIBRARIES = libpkzo.la

libpkzo_la_CXXFALGS = ...
libpkzo_la_LDADD = ...
libpkzo_la_SOURCES = ...

Libtool 提示:

*** Warning: linker path does not have real file for library -lSDL2main.
*** I have the capability to make that library automatically link in when
*** you link to this library. But I can only do this if you have a
*** shared version of the library, which you do not appear to have
*** because I did check the linker path looking for a file starting
*** with libSDL2main and none of the candidates passed a file format test
*** using a file magic. Last file checked: /usr/local/lib/libSDL2main.a

*** Since this library must not contain undefined symbols,
*** because either the platform does not support them or
*** it was explicitly requested with -no-undefined,
*** libtool will only create a static version of it.

猜猜 libSDL2main.a 是一个静态库,没有 DLL。

有没有一种方法可以使用 automake 构建 DLL,而不是使用 libtool 或告诉 libtool 停止无事生非?

PS:在有人提到它之前,我正在使用 LT_INIT([shared static win32-dl​​l])

配置 libtool

最佳答案

对于第一个问题,请确保您安装了共享版本的 SDL 库。

如果您绝对必须将您的 DLL 链接到静态库,您可以通过编辑 libtool 脚本来欺骗 libtool 来完成它。例如,如果您希望所有 依赖库静态链接到您的 DLL,您可以通过将其放在 configure.ac 的末尾来实现:

sed -i '/^whole_archive_flag_spec=/s/"$/ \\${wl}-static"/' libtool

现在,这是一个严重的 hack,依赖于 libtool 现在构建命令行的特定方式,因此不能保证它会继续工作——但它确实可以与 libtool 2.4.2 一起工作。由于您只有一个要静态链接的库,因此您可以通过稍微不同地应用 sed 来实现这一点。可能你会想要

sed -i '/^whole_archive_flag_spec=/s/"$/ \\${wl}-static \\${wl}-lSDL2main \\${wl}-shared"/' libtool

为了与您拥有的任何其他共享库保持共享链接,然后您需要将 -lSDL2main 从您拥有的任何地方取出。这很笨拙,但您尝试做的事情也很笨拙,而 libtool 不是为此而设计的。

对于第二个问题,将-no-undefined添加到libpkzo_la_LDFLAGS

关于windows - libtool 和 Windows DLL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20143412/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com