Constructors of library objects doesn't get called

Rüdiger Ranft _rdi_@web.de
Tue Mar 21 13:29:00 GMT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi list,

I figured out a stange behavior, when a progamm is linked aginst a lib
archive. If there are object files in the archive, which have
constrution functions, they do not get called, unless some other symbol
of the object file is referenced by the using program. When the linking
is done directly with the .o files instead an .a file, the ctors are
called. Also the ctors are get called when a symbol of the library is
referenced from another program part. So I guess when there is no
referencing part to the library during linking, the whole archive gets
silently dropped by the linker.

I attached a test case for this behavior, which builds 4 demonstration
programs:
~    | Residence of i | link    | result
- ----+----------------+---------+-------
vll | lib            | lib     | ok
vlo | lib            | objects | ok
vpl | program        | lib     | BAD
vpo | program        | objects | ok

The main problem for me is that I use a tool for generating some
autoregistration stuff for a plugin system, which relies on the call to
the constructors of a c++ object inside the sources.

bye
Rudi.

PS: Please CC me, I'm not on the list

- --
GPG encrypted mails preferred.
GPG verschlüsselte Mails bevorzugt.
- ---> https://dsred.ccc.de/085/tkuev <----

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQERAwUBRCAAbCHRAwx/e+nvAQLVQwfgii8U2XYmraffip3qo8+Ra+BaTVOA4Vt2
54b1mqTKh4UTEu6F36pLxEY8ath1nisNdptGFrz/KI6Kqr/XNK6JhVwMZHbNUC02
17xTv4pr6nNrmlm1JT7rqkYlXaTjt/wnG2af5usXnf+BRwRAsxKN46aMeshDDVPd
3jxjEsoSevPg+g8G/Je3FlJ7NOdIN/QW5jz58re0xZW5YHfEHHylr4CW+nhf5Ri3
k/kP5YNqhvDcMyarj8C35z+89IgE4y5bFYVPfcWitoCt8HkHt3h6JZe7/D5MXy3b
OfDnqm/8QAweGs+nAGGAmP5B3vSJDKMkoRQa1nX7OL8IpXMs
=qaJ3
-----END PGP SIGNATURE-----
-------------- next part --------------
A non-text attachment was scrubbed...
Name: testcase.tar.bz2
Type: application/x-bzip2
Size: 669 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20060321/962c230e/attachment.bz2>


More information about the Gcc-help mailing list