Subject: Re: "-Ldir -lname" vs. "dir/"
To: Nick Hudson <>
From: Johnny Lam <>
List: tech-toolchain
Date: 03/18/2002 13:42:33
I'm going to try to reformulate with a simpler example to try to make
clearer what I perceive to be the problem.  The following example is
distilled from something I received in private email regarding problems
with packages having hidden dependencies on devel/gettext-lib.

Consider a package that builds and installs two things: and  Also, is linked against and
/usr/lib/  Also suppose I have the following on my system:

	/usr/lib/		# from the Citrus project
	/usr/lib/		# only on ELF
	/usr/lib/		# only on ELF

	/usr/pkg/lib/	# from the GNU gettext project
	/usr/pkg/lib/	# only on ELF
	/usr/pkg/lib/		# only on ELF

I'm a developer, so I installed the GNU gettext to check for
compatibility problems with using the Citrus one.

Now, when is linked at _build_ time, the following command is

	libtool cc -o -rpath /tmp/lib \ \
		-Wl,-R/usr/pkg/lib -L/buildlink/lib -lintl

which is converted on an ELF system (line-by-line) into:

	cc -shared -Wl,-soname -Wl, -o .libs/ \
		-Wl,-rpath -Wl,/path/to/.libs -L./.libs -lbase \
		-Wl,-R/usr/pkg/lib -L/buildlink/lib -lintl

Note that links against the libraries that we want, namely from the uninstalled location and from /usr/lib
(assuming that /buildlink/lib/ points to /usr/lib/
Note also that an extra path /path/to/.libs is added to the run-time
search path so that we can link and run programs, e.g. regression tests,
against without needing to install anything.

Now at _install_ time, a relink command is automatically executed by
libtool that converts into:

	cc -shared -Wl,-soname -Wl, -o .libs/ \
		-Wl,-rpath -Wl,/usr/pkg/lib -L/usr/pkg/lib -lbase \
		-Wl,-R/usr/pkg/lib -L/buildlink/lib -lintl

This new no longer links against the correct
We want the one that is in /buildlink/lib, but we get the one from
/usr/pkg/lib.  I have a patch for libtool that causes the following
to be executed at relink time instead:

	cc -shared -Wl,-soname -Wl, -o .libs/ \
		-Wl,-rpath -Wl,/usr/pkg/lib /usr/pkg/lib/ \
		-Wl,-R/usr/pkg/lib -L/buildlink/lib -lintl

Now we link against the correct again.  However, I don't
have a good fix for a.out systems, as with my proposed change to libtool,
the relink command executed is:

	ld -Bshareable -o .libs/ \
		-R/usr/pkg/lib /usr/pkg/lib/ \
		-R/usr/pkg/lib -L/buildlink/lib -lintl

Here again, we link against the correct libraries, but unfortunately,
this breaks if we link programs against, but then update
the shared library to 0.1, because (as tested on NetBSD/mac68k)
the program hardcodes needing exactly the 0.0 version of  I
uncertain what the proper workaround on a.out systems looks like.


	-- Johnny Lam <>