[Top][All Lists]

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

RE: A portable way to link in all objects

From: Howard Chu
Subject: RE: A portable way to link in all objects
Date: Wed, 28 May 2003 12:02:35 -0700

> -----Original Message-----
> From: address@hidden
> [mailto:address@hidden Behalf
> Of Ronald
> Landheer-Cieslak
> Sent: Wednesday, May 28, 2003 6:00 AM
> To: address@hidden
> Subject: A portable way to link in all objects
> Hello all,
> I am looking for a way to portably tell libtool to link in
> all objects of
> a given static library. Basically, my problem is this:
> I have an object file containing "constructor" and "destructor"
> functions, which are not called from any program using my library, but
> which are run automagically at startup (constructor) or shutdown
> (destructor) time. Under gcc, this is implemented using
> __attribute__((constructor)) resp. __attribute__((destructor)).
> This scheme works like a charm when my libraries are shared:
> the program
> using the library loads the library into memory and the
> proper functions
> are automagically run. However, when the library is not
> shared, the object
> files containing the constructor and destructor functions
> don't get linked
> into the program, because the program has no business calling
> anything in
> the corresponding source file - and so doesn't. Hence, the
> constructor
> function doesn't get called at startup and all hell breaks loose.
> One way I've thought about to work around this thing is to
> make a static
> object of which the constructor does its thing, resp. the
> destructor does
> its thing, for which I put an "extern" in the library's
> (only) API header
> file. This will probably work and, as most of the library is
> written in
> C++ anyway, will probably do as a solution. However, I was
> hoping there is
> some option I've overlooked in Libtool that makes static
> libraries and
> shared libraries behave the same in this respect - i.e. be linked
> completely into an executable (considering a shared library
> an executable
> as per the Libtool paradigm). Though this option would not be
> "satisfactory" in all situations, it would help here.

Link all of the static archive members into a single object file. This works
on all platforms:
        (mkdir foo; cd foo; ar x ../libx1.a; ld -r -o ../libxx.o *.o)
        rm -rf foo; ar r libxx.a libxx.o

You don't need libtool to accomplish this.

  -- Howard Chu
  Chief Architect, Symas Corp.       Director, Highland Sun     
  Symas: Premier OpenSource Development and Support

reply via email to

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