Subject: Re: "-Ldir -lname" vs. "dir/"
To: Todd Vierling <>
From: Johnny Lam <>
List: tech-toolchain
Date: 03/13/2002 13:45:57
On Wed, Mar 13, 2002 at 10:53:12AM -0500, Todd Vierling wrote:
> On Tue, 12 Mar 2002, Johnny Lam wrote:
> : Is there a difference between the following commands?
> :
> : (a) cc -o bar.o -Wl,-R/usr/pkg -L/usr/pkg -lfoo
> : (b) cc -o bar.o -Wl,-R/usr/pkg /usr/pkg/
> There's no difference, but you made three unrelated mistakes in these
> examples:
> * /usr/pkg/lib, not /usr/pkg
> * the -soname argument is missing for libbar
> * the -shared option is missing

Yes, thanks for pointing those out.  I was typing these lines off the
top of my head, and I forgot a few essential bits.

> : Similarly, on an a.out system, suppose I have the following files:
> :
> : 	/usr/pkg/lib/
> :
> : Is there a difference between the following commands?
> :
> : (a) ld -Bshareable -o bar.o -R/usr/pkg -L/usr/pkg -lfoo
> : (b) ld -Bshareable -o bar.o -R/usr/pkg /usr/pkg/
> `Test it.'  I believe there is a difference, but I don't have a system
> available on which to check.

I was able to test on a NetBSD-1.5.1/mac68k machine, and they do both
generate the shared library; however, I'm not sure how to
tell what ware the interlibrary dependencies recorded in  On
the ELF system, I was able to run "ldd" and discover the
dependencies, but that doesn't work on the a.out system.  Do I have to
link an executable against and run "ldd" on the executable to
discover the dependencies?

> FROM MEMORY ONLY, may be incorrect:  The a.out linker, in case (a), will
> encode a major number and minimum minor number for use by the runtime
> linker.  However, if a full filename as in case (b) is given with
> .major.minor, only that specific library pathname will be usable -- any
> library with an incremented minor number will not link.

Given how pkgsrc works, that would be bad.  I'll try some tests on the mac68k,
but will those results be representative for all NetBSD/a.out platforms?

> There's another possible difference, but you'd need to test it, as I've
> never checked NetBSD's a.out linker for this:  Some linkers will encode the
> full path provided in case (b) into the dependent, rather than just a
> libname, resulting in a binary that has an absolute path (which would be bad
> for multiple libtooled libraries built together in one tree).  In such
> cases, rpath and LD_LIBRARY_PATH are unusable for finding the shared object
> if it moves.

Yes, I've read through many, many times, and this is taken care of
for those other linkers.  I'm only worried about linkers like NetBSD's that
don't hardcode library pathnames unless they're specified in a -R or --rpath
on the command line.

> : I am trying to solve a problem involving the use of libtool in pkgsrc.
> Could you describe the problem?

It involves the interaction between libtool and buildlink.  When a package
uses libtool to create two shared libraries and, one
depending on the other as above, and then uses libtool to install them into
/usr/pkg/lib, then is relinked prior to the actual installaion so
that it can find in /usr/pkg/lib.  Currently, it relinks by doing
(a), but I want it to do (b) instead, as then I don't accidentally link
against other libraries accidentally as in the following scenario:

	User has:

		/usr/lib/		[system supplied ]
		/usr/lib/		[  OpenSSL-0.9.5a]

		/usr/pkg/lib/		[pkgsrc-supplied ]
		/usr/pkg/lib/	[  OpenSSL-0.9.6b] explicitly needs the old OpenSSL libraries, and has
	the following dependencies: /usr/pkg/lib/

	The relink command for does:

		cc -shared -Wl,-soname -Wl, -o \
			-L/usr/pkg/lib -lfoo -lssl -lcrypto

But this relink command will link against the wrong OpenSSL libraries.  If
instead, it executed:

		cc -shared -Wl,-soname -Wl, -o \
			/usr/pkg/lib/ -lssl -lcrypto

then I could control which libraries to link against more accurately.


	-- Johnny Lam <>