Subject: Re: buildlink and libtool .la files [was Re: CVS commit: pkgsrc/mk]
To: Nick Hudson <>
From: Johnny C. Lam <>
List: tech-pkg
Date: 04/04/2002 00:58:00
On Wed, Apr 03, 2002 at 10:39:55AM +0100, Nick Hudson wrote:
> On Wednesday 20 March 2002 2:00 pm, Johnny Lam wrote:
> > On Wed, Mar 20, 2002 at 09:30:30PM +1000, Rene Hexel wrote:
> > > 
> > >   Can you please back this out again or fix it?  At least on i386 this
> > > causes all buildlinked packages that link against libintl to horribly
> > > fail!  At the moment there is a ton of packages that no longer build
> > > because of this.
> > 
> > I'm struggling with this because I don't see this problem on my machine.
> > I'll back it out, but can you aid in debugging why this is causing things
> > to break?
> What's the plan with this change that is needed for Solaris/a.out platforms?

I've think I've discovered the source of the problem that described by Rene
and also in pkg/15964.  I'll try to restate the problem.  Suppose you have
(on ELF):


	/usr/pkg/lib/	<-------- libtool archive


	${BUILDLINK_DIR}/lib/libintl.a      --> /usr/lib/libintl.a
	${BUILDLINK_DIR}/lib/     --> /usr/lib/
	${BUILDLINK_DIR}/lib/   --> /usr/lib/
	${BUILDLINK_DIR}/lib/ --> /usr/lib/

	${BUILDLINK_DIR}/lib/libbase.a      --> /usr/pkg/lib/libbase.a
	${BUILDLINK_DIR}/lib/     --> /usr/pkg/lib/
	${BUILDLINK_DIR}/lib/     --> /usr/pkg/lib/
	${BUILDLINK_DIR}/lib/   --> /usr/pkg/lib/
	${BUILDLINK_DIR}/lib/ --> /usr/pkg/lib/

The libtool archives in ${BUILDLINK_DIR} are created by the code in that is delimited by checks for _BUILDLINK_LIBTOOL_ARCHIVE.
They're just the installed libtool archives run through sed to replace
/usr/pkg/lib/ with ${BUILDLINK_DIR}/lib/

Now suppose you want to link against both and  You execute:

	libtool --mode=link -o ext.lo \
		-L${BUILDLINK_DIR}/lib -lbase -lintl

What you want is:

	cc -shared -nodefaultlibs .libs/ext.o \
		-Wl,--rpath -Wl,/usr/pkg/lib -L${BUILDLINK_DIR}/lib \
		/usr/pkg/lib/ -lintl \
		-Wl,-soname -Wl, .libs/

but what you actually get is (tested using the nb8 version of libtool):

	cc -shared -nodefaultlibs .libs/ext.o \
		-Wl,--rpath -Wl,/usr/pkg/lib -L${BUILDLINK_DIR}/lib \
		/usr/pkg/lib/ /usr/pkg/lib/ \
		-Wl,-soname -Wl, .libs/

Note the difference in the third line in that we want to link against the that is in ${BUILDLINK_DIR}, but instead we link against the in /usr/pkg.  Also note that despite having
-L${BUILDLINK_DIR}/lib come before all of the libraries that it still won't
links against the correct

The line that causes this is line 2633 of /usr/pkg/bin/libtool:

          newlib_search_path="$newlib_search_path $absdir"

In the libtool script, "absdir" is set to the location of the true
installed location of a .la file, so for above,
$absdir == /usr/pkg/lib.  "newlib_search_path" is used in the libtool
script to find when it encounters "-lNAME" on the command line.
The result of the above line is that when libtool sees
"-L${BUILDLINK_DIR}/lib -lbase", it correctly turns it into
"/usr/pkg/lib/", but it also adds "/usr/pkg/lib" to the search
path, so that when libtool then encounters "-lintl", it will find
/usr/pkg/lib/ and prefer it over the libintl libraries in

I'd trying the understand the ramifications of removing this line from
libtool.  It appears to be safe, but I haven't yet tried my test case of
rebuilding KDE2 yet.

Nick, do you have any thoughts on this?  I haven't check on the libtool
mailing list, yet, but I will soon.

	-- Johnny Lam <>