[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Building a static library consisting of libraries
From: |
Ralf Wildenhues |
Subject: |
Re: Building a static library consisting of libraries |
Date: |
Tue, 13 Jun 2006 09:03:05 +0200 |
User-agent: |
Mutt/1.5.11 |
* Norbert Sendetzky wrote on Mon, Jun 12, 2006 at 08:59:07PM CEST:
> On Monday 12 June 2006 12:57, Ralf Wildenhues wrote:
> > Mixing Libtool and non-Libtool libraries isn't the best idea. Better to
> > mix libtool libraries
> > lib_LTLIBRARIES = libfoo.la
> >
> > and libtool static libraries
> > lib_LTLIBRARIES = libbar.la
> > libbar_la_LDFLAGS = -static
> >
> > and libtool convenience archives
> > noinst_LTLIBRARIES = libbaz.la
>
> Let me first ask a question: Are .a libraries (libopendbx.a) static
> libraries
Usually, yes. (Exceptions: on w32, static libraries may end in .lib, on
AIX libraries in .a may be shared.)
But I think you are asking about the Automake/Libtool abstraction:
there, the model is:
libfoo.a is always a static library
libfoo.la is a Libtool abstraction that can be any of the three
mentioned above.
If you use Libtool, it's better to not use the .a libraries at all --
libtool static libraries provide this then.
> or is that only dependent on the -static flag?
When you create a library, the link flag -static to libtool means that
it should create only a static library.
> I ask because
> my understanding may be wrong, which depends on automake creating .a
> files if --enable-static is used.
Yes. Without -static, libtool may create a shared library, a static, or
both, depending on the system's features, configure flags, link flags.
> > If with this information you still get errors, then please show
> > what's going wrong in more detail (link command lines plus output,
> > and/or Makefile.am snippets; cut and paste is much more helpful
> > than describing errors; of course a reproducible example is best).
>
> My Makefile.am in lib:
>
> include_HEADERS = odbx.h
>
> lib_LTLIBRARIES = libopendbx.la
> libopendbx_la_SOURCES = odbxlib.c odbxlib.h odbx.c odbxdrv.h
> libopendbx_la_CFLAGS = @PKGCFLAGS@
> libopendbx_la_CPPFLAGS = -DLIBPATH=\"$(pkglibdir)/\"
> libopendbx_la_LDFLAGS = -version-info @LIBVERSION@
>
> lib_LIBRARIES = libopendbx.a
> libopendbx_a_SOURCES = odbxlib.c odbxlib.h odbx.c odbxdrv.h
> libopendbx_a_CFLAGS = @PKGCFLAGS@
> libopendbx_a_CPPFLAGS = -DODBX_STATIC
> libopendbx_a_LDFLAGS = -static
> libopendbx_a_LIBADD = $(top_builddir)/backends/mysql/libmysqlstatic.la
>
>
> A Makefile.am of a backend:
>
> pkglib_LTLIBRARIES = libmysqlbackend.la
> libmysqlbackend_la_SOURCES = mysqlbackend.c mysqlbackend.h
> libmysqlbackend_la_CFLAGS = @PKGCFLAGS@
> libmysqlbackend_la_LDFLAGS = -module -version-info @LIBVERSION@
> libmysqlbackend_la_LIBADD = address@hidden@
>
> noinst_LTLIBRARIES = libmysqlstatic.la
> libmysqlstatic_la_SOURCES = mysqlbackend.c mysqlbackend.h
> libmysqlstatic_la_CFLAGS = @PKGCFLAGS@
> libmysqlstatic_la_CPPFLAGS = -DODBX_STATIC
> libmysqlstatic_la_LDFLAGS = -static
> libmysqlstatic_la_LIBADD = address@hidden@
>
>
> This generates an invalid libopendbx.a which contains the libopendbx object
> and an invalid libmysqlstatic.la file:
You should never add libtool libraries to non-libtool libraries.
If you want libmysqlstatic to end up completely subsumed into
libopendbx, then make the former a libtool convenience archive, and the
latter a libtool library (static or not).
But you should note that @LIBMYSQL@ will not end up subsumed in
libopendbx, if @LIBMYSQL@ is not a convenience archive (which implies
that it is uninstalled). This would easily get you duplicate symbols,
if your resulting libopendbx would then be linked together with other
libraries depending on @address@hidden However, the libtool library will
contain the dependency information on @LIBMYSQL@, so this:
> make[2]: Entering directory `/home/nose/Project/opendbx/devel/test'
> /bin/sh ../libtool --tag=CC --mode=link gcc -std=gnu99 -g -O2 -o
> odbxtest-static odbx-regression.o ../lib/libopendbx.a
> gcc -std=gnu99 -g -O2 -o odbxtest-static
> odbx-regression.o ../lib/libopendbx.a
> ../lib/libopendbx.a(libopendbx_a-odbxlib.o):(.data+0x4): undefined reference
> to `mysql_odbx_ops'
should then work.
OK now?
Cheers,
Ralf