global objects in a static library not exported

John R Pretz
Fri Aug 28 20:19:00 GMT 2009


I'll give it a whirl.  It worked perfectly on my little test.



On Fri, Aug 28, 2009 at 8:07 AM, Ian Lance Taylor<> wrote:
> John R Pretz <> 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 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

More information about the Gcc-help mailing list