> -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Behalf > Of Ronald > Landheer-Cieslak > Sent: Wednesday, May 28, 2003 6:00 AM > To: [EMAIL PROTECTED] > 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 http://www.symas.com http://highlandsun.com/hyc Symas: Premier OpenSource Development and Support _______________________________________________ Libtool mailing list [EMAIL PROTECTED] http://mail.gnu.org/mailman/listinfo/libtool