This is the mail archive of the cygwin mailing list for the Cygwin 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: g++ 3.4.4: all global constructors in archive not called


Patric Ljung <plg <at> itn.liu.se> writes:

> 
> Dear cygwin readers,
> 
> I have just ported an application from Linux to Cygwin.
> In one archive (.a) I have several global constructors,
> 2-3 in two .o files.  When I run my program only one
> initializer function is called in that archive. Leaving
> the other uninitialized/uncalled.

I don't believe this is a cygwin issue, but in any case... linking to an archive
file is not the same thing as linking to all the .o files it contains. When you
link to an archive file, the linker only pulls in those object files that
contain symbols it needs for the link. This is so you can link to a large
archive without worrying that code irrelevant to your project will be linked as
well. The linker won't include a .o file simply because that file has local
static objects with constructors that need to be called. You have to redesign
the source structure to enforce that that .o file needs to be included for
another reason, or explicitly include it in the build (as opposed to having it
be part of an archive). If an .o file is never used, the linker assumes you
don't care about the side effects of any objects created in that file. If your
linker on a different platform behaves differently, I find that surprising, but
perhaps it is allowed.

-Lewis


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


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