From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marc Espie To: ROGER.K.WELLS@saic.com Cc: gcc@gcc.gnu.org Subject: Re: shared library, init Date: Fri, 21 Sep 2001 16:51:00 -0000 Message-id: <200109212350.f8LNolN25875@quatramaran.ens.fr> References: <00d301c14103$3c921b00$f05a798b@mtg.saic.com> X-SW-Source: 2001-09/msg00864.html In article < 00d301c14103$3c921b00$f05a798b@mtg.saic.com > you write: >When I use the linker flag, -Wl,-init, the linker complains that my _init() >conflicts with one in crti.o. When I give the -init flag the name of a >function that I supply it is ignored. Can someone advise me of the correct >syntax to establish a shared library initialization (& termination) >function. In the gcc context, assuming this is C, see attribute constructor and destructor in the gcc documentation. For C++, this is even more trivial. This assumes you're running gcc on a platform with full support for this (which is either provided directly by ld + ELF or by collect2 usually). Note that the semantics are a bit hard to guarantee and check: it is often unknown in which order several initialisation routines will be run (and how many times), and it is even harder to be sure that a finalization routine will actually be run...