[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
What makes a convenience library (use --whole-archive)?
From: |
Michael Poole |
Subject: |
What makes a convenience library (use --whole-archive)? |
Date: |
Tue, 7 Jun 2011 21:07:22 -0400 |
Some of the files in my convenience libraries have static
initializers. By default, the linker discards these symbols because
they are not referenced. I am trying to figure out how to keep them
in an automake-driven build.
Mailing list threads I have seen on the Internet, plus the "libtool"
script code (as of version 2.2.6b), indicate that convenience
libraries should be linked with -Wl,--whole-archive (or the
equivalent). I do not see that here.
In a reduced test case, my Makefile.am looks like this:
ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = foreign
noinst_LTLIBRARIES = libsubdir.la
libsubdir_la_LDFLAGS = -static
libsubdir_la_SOURCES = subdir/item.cpp
noinst_PROGRAMS = test
test_SOURCES = test.cpp
test_LDADD = libsubdir.la
And the final link stage looks like this:
/bin/sh ./libtool --tag=CXX --mode=link g++ -g -O2 -o test
test.o libsubdir.la
libtool: link: g++ -g -O2 -o test test.o ./.libs/libsubdir.a
.. and the static initialization code in subdir/item.cpp is not called.
What am I overlooking (or doing wrong)?
(For completeness, the reduced configure.ac looks like this:
AC_INIT([lttest], [1.0])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR([test.cpp])
AM_INIT_AUTOMAKE([-Wall -Werror])
LT_INIT([static disable-shared])
AC_PROG_CXX
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
test.cpp has an empty main() and subdir/item.cpp contains a static
instance of a class that prints "Hello world" in its constructor.)
Michael Poole
- What makes a convenience library (use --whole-archive)?,
Michael Poole <=