Rüdiger Ranft writes: > 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. If a file is wholly unreferenced it won't be included: this is desirable linker behaviour. Do this: ~/testcase $ gcc -o vpl zzz.o -Wl,-whole-archive libblubb.a -Wl,-no-whole-archive ~/testcase $ ./vpl i=42 This isn't a gcc but a binutils issue. Andrew.