global objects in a static library not exported

John R Pretz john.pretz@gmail.com
Thu Aug 27 16:25:00 GMT 2009


Hi,

I have a global object instantiated in a source file.  Depending on
how the resulting object file is linked, that global object is
successfully created or not.  It appears that gcc quite sensibly
doesn't link in symbols that aren't used.

I'm attaching an example showing off my question.  The executable is
built two ways.  In the first way, it is build via a static library to
which the final executable is linked.  In the second way, the object
files are just all compiled together skipping the library.  There is a
global object (in global_object.cc) which I want to get created before
main() starts and it does not work if I build the executable by
linking against the static library.

I'm trying to create a little system where some of my software
components can register themselves automatically, so to work they way
I want it to I am not really free to re-arrange the source.

If anybody has any insight into how to make this work, I'd appreciate
it.  is there some linker flag to get these unreferenced global
objects created?

Thanks,

John
-------------- next part --------------
A non-text attachment was scrubbed...
Name: global-object.tgz
Type: application/x-gzip
Size: 653 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20090827/9a96f9b8/attachment.bin>


More information about the Gcc-help mailing list