automake
[Top][All Lists]
Advanced

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

Re: building a shared library that depends on a static library


From: Simon Richter
Subject: Re: building a shared library that depends on a static library
Date: Fri, 03 Mar 2006 18:47:55 +0100
User-agent: Debian Thunderbird 1.0.7 (X11/20051019)

Hi,

Jason Kraftcheck wrote:

Automake includes the contents of the $LIBS variable in all link commands,
including linking libraries.  This results in the following behavior:

3) If libtool is creating a shared library, and one or more of the libraries in
$LIBS is static, behavior is *incorrect*.  libtool links the objects in the
static archives into the resulting shared library.  As static archives are
typically compiled w/out PIC, the result is a broken shared library.

Hm. I have an actual use case where it may be desired to do that, even:

I have a C++ wrapper library around libltdl, providing a "PluginLoader" class that has a static member that on initialisation registers the preloaded symbols, and a constructor that takes the address of the object. Obviously, this needs to happen in the main program, which I would like to not know about the plugin loader if it doesn't use it directly (but a library does).

Now I have my libfoo library, which uses plugins, and extends the PluginLoader class to not only load the objects but also do some higher-level init stuff. This library now has a reference to the PluginLoader constructor, so if a .a library is linked, the constructor is pulled into the link, which pulls in the static object and the static initializer, which is wrong for at least three reasons: non-PIC code, globals in a library, and an undefined reference from the library to the main program's lt_preloaded_functions symbol, which it may not even have if not linked with libtool and -dlopen.

The obvious solution is the proposed one: The plugin loader code is static-only, and all libraries using it depend on it. When the main program is linked using libtool, it will pull in the static library, which knows to initialize ltdl once, and correctly. The only thing not solved is that libfoo still has an undefined symbol (PluginLoader::PluginLoader()) that has to be resolved from the main program.

   Simon




reply via email to

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