使用Libtool强制将静态库链接到共享库中

使用Libtool强制将静态库链接到共享库中

问题描述:

我有一个库( libfoo ),该库使用libtool 编译为两个对象:libfoo.a和libfoo.so.

I have a library (libfoo) that is compiled using libtool into two objects: libfoo.a and libfoo.so.

我还必须使用libtool 创建另一个库( libbar ),它将是一个包含所有libfoo代码的单个共享库(libbar.so).

I have to create, using libtool also, another library (libbar) that will be a single shared library (libbar.so) containing all libfoo's code.

为此,我必须强制 libbar 链接到 libfoo.a ,而不是libfoo.so.

In order to do this, I have to force libbar to link against libfoo.a, and not libfoo.so.

我处于 autotools 环境中,因此必须使用标准的 configure.in Makefile.am 规则来解决此问题.

I am in an autotools environment, so I have to solve this using standard configure.in or Makefile.am rules.

我尝试了几件事,例如在configure.in中:

I tried several things, like in configure.in :

LDFLAGS="$LDFLAGS "-Wl,-Bstatic -lfoo -Wl,-Bdynamic"

这总是在链接行上产生-Wl标志;但-lfoo已消失,并已以绝对路径形式(/opt/foo/lib/libfoo.so )放在其开头.

That always results in the -Wl flags on the linking line; but -lfoo has disappeared and has been placed in an absolute-path form (/opt/foo/lib/libfoo.so) at the beginning of it.

我也尝试过:

LDFLAGS="$LDFLAGS "-L/opt/foo/lib libfoo.a"

或在Makefile.am中:

or in Makefile.am:

libbar_la_LDADD = -Wl,-Bstatic -lfoo -Wl,-Bdynamic

libbar_la_LTLIBRARIES = libfoo.a

etc等(有很多变种!)

etc etc (with many, many variants !)

但是我认为我当然对Autotools/Libtool的知识不足,无法单独解决此问题.我一直无法在网上找到有关此问题的信息,而问题总是略有不同.

But I think that definitely I do not have knowledge enough of Autotools/Libtool to solve this alone. I have not been able to find information on the Net about it, always slightly different issues.

您可能会使用

You could probably use a convenience library. Convenience libraries are intermediate static libraries which are not installed. You could use the prefix noinst to build one.

noinst_LTLIBRARIES = libfoo_impl.la

lib_LTLIBRARIES = libfoo.la libbar.la
libfoo_la_LIBADD = libfoo_impl.la
libbar_la_LIBADD = libfoo_impl.la