This is the mail archive of the gcc-help@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]
Other format: [Raw text]

Re: global objects in a static library not exported


John R Pretz <john.pretz@gmail.com> writes:

> 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.

This is standard Unix linker behaviour for archives.

> 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?

You use the --whole-archive option to direct the linker to pull in every
object from an archive.  You would normally use --whole-archive around
th archives you want to pull in entirely, ending with
--no-whole-archive.

Ian


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