From owner-freebsd-hackers Sat Mar 13 12:17:47 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from wall.polstra.com (rtrwan160.accessone.com [206.213.115.74]) by hub.freebsd.org (Postfix) with ESMTP id B1F8C14E37 for ; Sat, 13 Mar 1999 12:17:45 -0800 (PST) (envelope-from jdp@polstra.com) Received: from vashon.polstra.com (vashon.polstra.com [206.213.73.13]) by wall.polstra.com (8.9.1/8.9.1) with ESMTP id MAA00303; Sat, 13 Mar 1999 12:17:25 -0800 (PST) (envelope-from jdp@polstra.com) From: John Polstra Received: (from jdp@localhost) by vashon.polstra.com (8.9.2/8.9.1) id MAA64976; Sat, 13 Mar 1999 12:17:25 -0800 (PST) (envelope-from jdp@polstra.com) Date: Sat, 13 Mar 1999 12:17:25 -0800 (PST) Message-Id: <199903132017.MAA64976@vashon.polstra.com> To: gram@cdsec.com Subject: Re: C++ global constructors and shared libraries In-Reply-To: <36E6AB40.742D64BB@cdsec.com> Organization: Polstra & Co., Seattle, WA Cc: hackers@freebsd.org Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG In article <36E6AB40.742D64BB@cdsec.com>, Graham Wheeler 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