加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

libtool和Windows DLL

发布时间:2020-12-14 05:42:38 所属栏目:Windows 来源:网络整理
导读:我与GNU autotools有着艰难的关系,尤其是libtool.但是因为它们在可移植性和交叉编译方面起了作用,我开始再次使用它们. 不幸的是我无法使用libtool来构建正确的Windows DLL.然而,香草制造gcc 我会很高兴为我构建DLL. 例如: LIBEXT = .dllpkzo$(LIBEXT): $(pa
我与GNU autotools有着艰难的关系,尤其是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 $@

将haily建立一个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配置libtool([shared static win32-dl??l])

解决方法

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

如果绝对必须将DLL链接到静态库,则可以通过编辑libtool脚本来欺骗libtool.例如,如果您希望所有依赖库与您的DLL静态链接,您可以通过[在configure.ac结尾处这样做:

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

现在,这是一个严重的黑客,并依赖于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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读