为什么Libtool不想与静态库链接?

Gab*_*abi 6 build-automation automake build autotools libtool

我想构建一个使用GNU Autotools使用ZipArchive的共享库,但我遇到了这个问题:

Warning: linker path does not have real file for library -lziparch.
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 libziparch and none of the candidates passed a file format test
using a file magic. Last file checked: /usr/local/ZipArchive/ZipArchive/libziparch.a
The inter-library dependencies that have been dropped here will be
automatically added whenever a program is linked with this library
or is declared to -dlopen it.

如果我构建一个静态库或者如果我使用ZipArchive的共享库它可以工作,但问题是ZipArchive源代码附带的makefile只构建一个静态库.

如何强制Libtool与静态库链接?

小智 5

通常,静态归档是使用非pic对象文件创建的,不能将它们放入共享库中。

该消息告诉您的是,当程序使用Libtool链接到您的库时,-lziparch将被添加到链接中。因此,除非您要为解释语言构建模块,否则您无需进行任何更改。在这种情况下,您将必须将ZipArchive构建为共享库。此外,这在MS Windows之类的平台上不起作用,在该平台上,共享库(DLL)必须在链接时解析其所有符号。

综上所述,如果您的ziparch静态库是PIC代码,则在将其链接到库时可以使用-whole-archive标志。但是,这将是最不便携的解决方案。