*BSD News Article 58235


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!nntp.coast.net!chi-news.cic.net!newsfeed.internetmci.com!in2.uu.net!news.accessone.com!not-for-mail
From: jdp@polstra.com (John Polstra)
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: ELF
Date: 27 Dec 1995 09:52:12 -0800
Organization: Polstra & Co., Seattle, WA
Lines: 33
Message-ID: <4bs14c$4ro@austin.polstra.com>
References: <4avq5m$7rk@complete.org> <4bghlm$7q3@pell.pell.chi.il.us> <4bn4i7$g0j@helena.MT.net> <4bnf2d$lhr@news.nynexst.com>
NNTP-Posting-Host: austin.polstra.com

In article <4bnf2d$lhr@news.nynexst.com>, H.J. Lu <hjl@gnu.ai.mit.edu> wrote:
> Under ELF, you don't have to do anything special to your C++ source
> to make file-scope constructors/destructors work with shared library.
> They even work with dlopen/dlclose.

Under FreeBSD, they also work with dlopen and dlclose.  That has been true
since well before FreeBSD-2.1 came out.  (However, I don't think it was
true for 2.0.5.)

Concerning special steps for building C++ shared libraries under
FreeBSD:  Basically, you have to make sure that /usr/lib/c++rt0.o gets
linked in.  The easiest way to do that, if you are using the standard
BSD make include files in /usr/share/mk, is to add the line

    CPLUSPLUSLIB = yes

to your Makefile.

I agree that, ideally, nothing like this should be necessary.  I
don't like it any better than you do, and I am going to look for
a way to eliminate the need for it under FreeBSD.  But I'm not so
sure it's possible, using the present a.out format.

I hope FreeBSD will eventually move to ELF.  It's clearly superior
to a.out.  The ease of supporting static constructors and destructors
is just one example.  But meanwhile, provided that you have an
up-to-date version of FreeBSD, you should be able to get _full_
functionality from shared libraries, even for C++.  If you find any bugs
in this area, please send me test cases.
-- 
   John Polstra                                       jdp@polstra.com
   John D. Polstra & Co., Inc.                Seattle, Washington USA
   "Self-knowledge is always bad news."                 -- John Barth