delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/02/20/21:41:35

X-Spam-Check-By: sourceware.org
Message-ID: <45DBB135.7090204@cwilson.fastmail.fm>
Date: Tue, 20 Feb 2007 21:40:53 -0500
From: Charles Wilson <cygwin AT cwilson DOT fastmail DOT fm>
User-Agent: Thunderbird 1.5.0.9 (Windows/20061207)
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: g++ 3.4.4: all global constructors in archive not called
References: <45DB5F00 DOT 5050501 AT itn DOT liu DOT se> <loom DOT 20070220T231605-979 AT post DOT gmane DOT org>
In-Reply-To: <loom.20070220T231605-979@post.gmane.org>
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

Lewis Hyatt wrote:
> Patric Ljung <plg <at> itn.liu.se> writes:
>> 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). 

Or, perhaps, try the --whole-archive linker option:

gcc -o my_prog.exe my_prog.o
     -Wl,--whole-archive my_lib.a -Wl,--no-whole-archive < other libs >

I don't know for sure if it will work, but it's worth a try.

--
Chuck

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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019