libtool和Windows DLL

rio*_*oki 5 windows dll libtool mingw32

我与GNU自动工具(特别是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 $@   
Run Code Online (Sandbox Code Playgroud)

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

但是,如果我像这样使用libtool:

lib_LTLIBRARIES = libpkzo.la

libpkzo_la_CXXFALGS = ...
libpkzo_la_LDADD    = ...
libpkzo_la_SOURCES  = ...
Run Code Online (Sandbox Code Playgroud)

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.
Run Code Online (Sandbox Code Playgroud)

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

有没有一种方法可以使用automake生成DLL,而不使用libtool或告诉libtool停止大惊小怪?

PS:在任何人提到它之前,我正在配置libtool LT_INIT([shared static win32-dll])

uck*_*man 1

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

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

sed -i '/^whole_archive_flag_spec=/s/"$/ \\${wl}-static"/' libtool
Run Code Online (Sandbox Code Playgroud)

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

sed -i '/^whole_archive_flag_spec=/s/"$/ \\${wl}-static \\${wl}-lSDL2main \\${wl}-shared"/' libtool
Run Code Online (Sandbox Code Playgroud)

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

对于第二个问题,添加-no-undefinedlibpkzo_la_LDFLAGS.