Subject: libtool, C++ shared libraries, and pthreads
To: None <>
From: Johnny C. Lam <>
List: tech-pkg
Date: 11/11/2004 15:22:10
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.

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?

Alternatively, we could modify pkgsrc to always pass "-lpthread" to
the linker if building a package with USE_LIBTOOL=YES and which also
includes  However, I believe that making
libtool do the right thing is the better fix.


	-- Johnny Lam <>