【问题标题】:libtool and Windows DLLslibtool 和 Windows DLL
【发布时间】:2013-12-07 05:56:49
【问题描述】:

我与 GNU 自动工具,尤其是 libtool 的关系很不好。但是因为它们在可移植性和交叉编译方面表现出色,所以我再次开始使用它们。

不幸的是,我无法让 libtool 构建正确的 Windows DLL。然而用香草制作 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-dll])配置libtool

【问题讨论】:

  • 我在尝试在 Fedora 上交叉编译 Quake 克隆时遇到了同样的问题。赞成的答案是否低于您确定的解决方案?
  • 所以..有趣的故事。在为这个问题头疼了几个小时之后,我刚刚删除了从源代码构建 SDL、SDL_image 和 SDL_ttf 安装的愚蠢的 libSDL*.la libtool turds。突然之间,一切都愉快地重新连接起来。谢谢,libtool。真的。干得好。

标签: windows dll mingw32 libtool


【解决方案1】:

对于第一个问题,请确保您安装了 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 从您拥有的任何其他地方取出。这是 gimpy,但您尝试做的事情也是 gimpy,而 libtool 不是为此而设计的。

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

【讨论】:

  • 很遗憾,您不了解 SDL。 SDL2main.a 不能是共享库,因为它为应用程序提供主库。这是设计使然,有点烦人。
  • 也许用你自己的main() 构建呢?
  • 是的,不,也许... SDL2main 库的绝妙之处在于,您可以在 Windows 环境中使用“正常”的 main 函数而不会遇到任何问题。 (SDL 在适当的 WinMain 中进行了一些设置,这在图形应用程序中是必需的。)
  • 另外整个主题真的很烦人。为什么libtool在直接使用编译器时完全无法构建DLL是小菜一碟。
  • 如果您的目标是 one 构建配置,这只是小菜一碟。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-27
  • 1970-01-01
  • 2014-04-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多