This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: global objects in a static library not exported
- From: Ian Lance Taylor <iant at google dot com>
- To: John R Pretz <john dot pretz at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Fri, 28 Aug 2009 07:07:15 -0700
- Subject: Re: global objects in a static library not exported
- References: <4b80e8370908262059l4e96c04aqe9ce5c45ed81884@mail.gmail.com>
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