automake
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problems with libtool convenience libraries and automake


From: Kent Boortz
Subject: Problems with libtool convenience libraries and automake
Date: Mon, 09 Apr 2007 18:55:18 +0200
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.2 (darwin)

Hi,

I build using "-static" given to libtool when creating executables, to
link statically with our own libraries, but dynamically against system
libraries. Works nicely, except one small problem.

One library, lets call it "libstat", I always want to compile static and
install in the more private "pkglib" directory. But it is also to be
used in the build itself as a libtool convenience library, when
creating other shared libraries and executables.

Problem is, I also want to create another shared library "libdyn" that
use objects in "libstat". I have included a small test setup below.

What happens is that the executable gets a dependency on
"libstat.so.0", something I don't want and that I thought "-static"
when linking the executable took care of. If I change from
'pkglib_LTLIBRARIES' to 'noinst_LTLIBRARIES' in
"libstatdir/Makefile.am" the dependency goes away, but I do want to
install the library, at least the static version of it.

So I go use "libstat_la_LDFLAGS = -static" but this has the effect of
just producing a non position independent static library, i.e. no
libtool convenience library is created (even if placed in ".libs").
And when linking the "libdyn" library, the linker on AMD64 will
complain

  gcc -shared  .libs/libdyn.o  ../libstatdir/.libs/libstat.a  -Wl,-soname 
-Wl,libdyn.so.0 -o .libs/libdyn.so.0.0.0
  /usr/bin/ld: ../libstatdir/.libs/libstat.a(libstat.o): relocation R_X86_64_32 
against \
  `a local symbol' can not be used when making a shared object; recompile with 
-fPIC

So how do I make all these happen?

  - The executable to link statically against the objects from
    "libstat".

  - The shared library "libdyn" link against the libtool convenience
    library in such a way it has no "libstat.so" dependency, but
    includes the objects from "libstat" (position independent of
    course).

  - The static library "libstat.a" is installed when "make install",
    but not a shared version.

Or to put the question differently, when using a convenience library,
can I control if the static or shared library is installed? And if
static or shared linking is used when referenced from other parts of
the build, both references from building executables and other
libraries?

I'm using

  libtool  1.5.22
  automake 1.9.6
  autoconf 2.60

I highly appreciate any help or pointers,

kent


==== DO ====

aclocal
libtoolize --automake --force --copy
automake --add-missing --force --copy
autoconf
./configure ; make clean ; make
for f in `find exedir -name exebin`; do
  echo "**** Running ldd on $f"
  ldd $f
done
for f in `find lib*dir -name "lib*.so"`; do
  echo "**** Running ldd on $f"
  ldd $f
done
for f in `find lib*dir -name "lib*.a"`; do
  echo "**** Found $f"
done

==== configure.in ====

AC_INIT([exeproj], [1.0], address@hidden)
AM_INIT_AUTOMAKE
AC_PROG_LIBTOOL
AC_CONFIG_FILES([Makefile exedir/Makefile
 libstatdir/Makefile  libdyndir/Makefile])
AC_OUTPUT

==== Makefile.am ====

AUTOMAKE_OPTIONS = foreign
SUBDIRS = libstatdir libdyndir exedir

==== exedir/Makefile.am ====

bin_PROGRAMS   = exebin
exebin_SOURCES = exefile.c
exebin_LDADD   = $(top_builddir)/libstatdir/libstat.la
exebin_LADD    = -static

==== libstatdir/Makefile.am ====

pkglib_LTLIBRARIES = libstat.la
# If line below replaces first line, deps are right, but no install
#noinst_LTLIBRARIES = libstat.la
libstat_la_SOURCES = libstat.c
# First and second try was without this line below
libstat_la_LDFLAGS = -static

==== libdyndir/Makefile.am ====

pkglib_LTLIBRARIES = libdyn.la
libdyn_la_SOURCES  = libdyn.c
libdyn_la_LIBADD   = $(top_builddir)/libstatdir/libstat.la

==== exedir/exefile.c ====

extern int libstatfunc(void);

int main()
{
  return libstatfunc();
}

==== libstatdir/libstat.c ====

int libstatfunc(void)
{
  return 42;
}

==== libdyndir/libdyn.c ====

extern int libstatfunc(void);

int libdynfunc(void)
{
  return libstatfunc();
}

-- 
Kent Boortz, Senior Software Developer
MySQL AB, www.mysql.com
Office: +46 18 174400 ext. 4450 (VoIP)
Office: +46 19 182931
Mobile: +46 70 2791171




reply via email to

[Prev in Thread] Current Thread [Next in Thread]