This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Shared library initializers

On Thu, May 03, 2001 at 11:05:27AM -0300, Alexandre Oliva wrote:
> On May  3, 2001, Jeff Parker <> wrote:
> > How do I the same thing using 'gcc' and/or 'ld' under LINUX?
> Give the function the ``constructor'' attribute, or name it _init(),
> or use the `-init SYMBOL' linker switch.

Using the 'constructor' attribute doesn't garantee that this is the
FIRST function to be called, prior to any other constructor of static
and global objects, is it?

Exporting a function _init() doesn't work for me:

>gcc-3.0 -shared _init.lo -Wl,-soname -Wl, -o .libs/
_init.lo: In function `_init':
/home/carlo/c++/libcw/src/libcwd/ multiple definition of `_init'
/usr/lib/crti.o(.init+0x0): first defined here
collect2: ld returned 1 exit status

It is not easy to get rid of the /usr/lib/crti.o as I want to use libtool,
and this is how libtool creates shared libraries.

In my case, even the linker option doesn't work :(.  When running a program,
first the _init() function of libstdc++ is called, this calls operator new
(from std::ios_base::Init::Init()) which is overloaded in my library: hence
my library is called *before* it is initialized (I need to initialize the
malloc part of my library).  I guess there is only one way: to check a
boolean *every* call to malloc to see if things are already initialized;
and from there call _init() myself to initialize the global objects that I
need.  Is there a way to call _init of a specific library?  How does that
work anyway, when every shared library defines a global function _init?.

Carlo Wood <>

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]