This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: C++ and static data members...


Martin Loewis writes:
> Well, you are missing an implementation restriction. You must not put
> the object files containing such globals in a library. Instead, you
> must pass them to the linking command line explicitly.
> 
> This is because of the way the linker works: it won't use object files
> from a library unless they are used.

That last sentence is not very clear.  What actually happens is that the
linker processes files and libraries on the command line left to right.
It will not select an object file from a library unless that object file
defines a global symbol that is currently undefined.  To oversimplify
things a bit, initially only the symbol "main" is undefined (really
it's a bit different: a startup function is chosen which calls main,
but it gives you a picture of what's going on).

If you want to be sure that a particular static object is included, you
can make sure that the .o file that contains it also defines some global
symbol that is referenced by some other file that must be included.




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]