help-gplusplus
[Top][All Lists]
Advanced

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

constructors not called in dynamic object, Linux only.


From: James Kanze
Subject: constructors not called in dynamic object, Linux only.
Date: Tue, 01 Feb 2005 21:33:42 +0100
User-agent: Mozilla Thunderbird 1.0 (X11/20041206)

Does anyone know what options are necessary for static
initializers in a dynamic object to be correctly executed under
Linux.

I have a couple of very simple dynamic objects with NO publicly
accessible symbols in them -- everything in an anonymous
namespace.  The constructor of a static object enrols the object
in a registry in the main code.  This works perfectly under
Solaris (with both Sun CC and g++); under Linux, however, the
constructors aren't getting called.

FWIW: the main program is compiled with:
    g++ -g -fPIC -c BasicInput.cc
    g++ -g -fPIC -c InputTranslator.cc
    g++ -g -fPIC -c main.cc
    g++ -g -fPIC -o ./test BasicInput.o InputTranslator.o main.o -ldl
and the dynamic object with:
    g++ -g -fPIC -c ASCIIInputTranslator.cc
g++ -g -fPIC -shared -mimpure-text -o ASCIIInputTranslator.so ASCIIInputTranslator.o

(The -mimpure-text was an experiment. It isn't necessary under
Solaris, and I get the same results with or without under
Linux.)

The g++ documentation for -shared has a footnote "On some
systems, gcc -shared needs to build supplementary stub code for
constructors to work. On multi-libbed systems, gcc -shared must
select the correct support libraries to link against. Failing to
supply the correct flags may lead to subtle defects. Supplying
them in cases where they are not necessary is innocuous."
Presumable, Linux is one of the cases where you need some
special option to make g++ generate these stubs (and Solaris
isn't). Regretfully, the doc doesn't seem to say what these
options are.


--
James Kanze                                      home: www.gabi-soft.fr
Conseils en informatique orientée objet/
                       Beratung in objektorientierter Datenverarbeitung
9 pl. Pierre Sémard, 78210 St.-Cyr-l'École, France +33 (0)1 30 23 00 34


reply via email to

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