Subject: Re: libtool, C++ shared libraries, and pthreads
To: None <jlam@netbsd.org>
From: Nick Hudson <skrll@netbsd.org>
List: tech-pkg
Date: 11/11/2004 15:47:02
On Thursday 11 November 2004 15:22, Johnny C. Lam wrote:
> On NetBSD 2.0, libtool doesn't correctly generate C++ shared libraries
> if the shared library should also link against -lpthread. Currently,
> libtool uses:
>
> g++ -shared -nostdlib $predep_objects $libobjs $deplibs \
> $postdep_objects $compiler_flags \
> ${wl}-soname $wl$soname -o $lib $postdeps
>
> to create the C++ shared library (see the definition of archive_cmd).
> The -nostdlib causes problems because any -pthread options passed to
> the compiler through libtool are ignored altogether as a result.
This is how libtool has done c++ linking for as long as I can remember. That
is, it attempts to determine the right objects and libraries to pull in adds
them to {pre,post}dep_objects and postdeps. This is clearly defeated by, e.g.
-pthread
> On NetBSD 2.0, the correct way to link shared libraries is with:
>
> g++ -shared $libobjs $deplibs $compiler_flags \
> ${wl}-soname $wl$soname -o $lib
>
> If the resulting shared library should also link against -lpthread,
> then it would suffice to pass -pthread to the libtool script, and it
> would be forwarded down to the g++ command line, and the command above
> would do the right thing.
>
> I would like to modify libtool to use the latter command to generate
> shared libraries for the CXX tag for NetBSD 2.0. The question is
> whether this command does the right thing on NetBSD<2.0. Although
> GCC on NetBSD 1.6.x doesn't support -pthread, I wonder if it properly
> adds the relevant /usr/lib/crt*.o objects, -lstdc++, etc. Can anyone
> clarify this for me, please?
There were points in the past where g++/gcc -shared didn't work. Around
1.3/1.4, iirc. I believe 1.6 DTRT.
I have seen some discussion of -pthread on the libtool ML, but I really don't
pay much attention these days.
Nick