Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 13 Mar 1999 12:17:25 -0800 (PST)
From:      John Polstra <jdp@polstra.com>
To:        gram@cdsec.com
Cc:        hackers@freebsd.org
Subject:   Re: C++ global constructors and shared libraries
Message-ID:  <199903132017.MAA64976@vashon.polstra.com>
In-Reply-To: <36E6AB40.742D64BB@cdsec.com>

next in thread | previous in thread | raw e-mail | index | archive | help
In article <36E6AB40.742D64BB@cdsec.com>,
Graham Wheeler  <gram@cdsec.com> wrote:
> Hi folks
> 
> I have just changed some C++ code libraries from static to shared. 
> I now find that some global objects declared in these libraries 
> are no longer having their constructors called. If I move the object
> declarations into the main.cc file, then they work fine. However, I
> don't want to do this for all the objects - we are talking about 15
> libraries here consisting of hundreds of .cc files that would have to be
> checked.
> 
> Is there some command line argument that I need for this, or is it 
> a problem with g++/ld on FreeBSD generally? I am using FreeBSD 2.2.7
> at present.

I bet I know what the problem is.  With a.out, you have to build your
shared libraries using "gcc -shared" -- not "ld -Bshareable".  There
is an extra start-up file "c++rt0.o" that must be linked into the
shared library in order for its global constructors / destructors to
be invoked. "gcc -shared" takes care of that for you automatically.

John
-- 
  John Polstra                                               jdp@polstra.com
  John D. Polstra & Co., Inc.                        Seattle, Washington USA
  "Self-interest is the aphrodisiac of belief."           -- James V. DeLong


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199903132017.MAA64976>