Topic: Adding extensions to library at link time
Author: ruchrist@online.no (Rune Christensen)
Date: 1997/07/21 Raw View
I have written a library system where I want the user / client to be
able to add extensions at link time. The extension should
automatically be added whenever a global function (or object /
variable) exists in the client code (Preferably it should be added to
some library array so that multiple extensions can be handled). This
to guarantee that extension has been hooked up already when
constructors for static objects are called, and so the client doesn't
have to make sure the extension has been added 'in time'.
I remember that for Borland C++ this could be implemented by defining
a dummy (empty) function in a library. If linker found that name in
earlier linked object file (or library?), it would ignore this second
instance.
Is this Borland C++ 'feature' standard C/C++? (Does standard say
anything relevant about linking?)
Can anyone suggest any other standard way to implement this?
Best regards,
Rune Christensen
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: "Paul D. DeRocco" <pderocco@ix.netcom.crud.com>
Date: 1997/07/22 Raw View
Rune Christensen wrote:
>
> I have written a library system where I want the user / client to be
> able to add extensions at link time. The extension should
> automatically be added whenever a global function (or object /
> variable) exists in the client code (Preferably it should be added to
> some library array so that multiple extensions can be handled). This
> to guarantee that extension has been hooked up already when
> constructors for static objects are called, and so the client doesn't
> have to make sure the extension has been added 'in time'.
>
> I remember that for Borland C++ this could be implemented by defining
> a dummy (empty) function in a library. If linker found that name in
> earlier linked object file (or library?), it would ignore this second
> instance.
>
> Is this Borland C++ 'feature' standard C/C++? (Does standard say
> anything relevant about linking?)
> Can anyone suggest any other standard way to implement this?
The proposed standard says nothing whatsoever about how linking works,
or even if there is any such thing as a library. However, the way
Borland handles libraries is pretty standard among systems that use
libraries, which is to say most systems.
The only way to guarantee initialization order of absolutely everything
is to put absolutely everything into one module (since the standard
doesn't define anything about how modules are ordered), or to use your
own explicit means of forcing initialization order.
--
Ciao,
Paul
(Please remove the extra "crud" from the return address,
which has been altered to foil junk mail senders.)
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]