gnu/96481: native ld(1) does not look for shared libs in LD_LIBRARY_PATH

Thomas Quinot thomas at
Fri Apr 28 16:40:19 UTC 2006

>Number:         96481
>Category:       gnu
>Synopsis:       native ld(1) does not look for shared libs in LD_LIBRARY_PATH
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Apr 28 16:40:12 GMT 2006
>Originator:     Thomas Quinot
>Release:        FreeBSD 6.1-RC i386
System: FreeBSD kani 6.1-RC FreeBSD 6.1-RC #0: Mon Apr 24 13:08:50 CEST 2006 root at kani:/usr/obj/usr/src/RELENG_6/sys/KANI i386

	According to man ld:

           The  linker  uses  the  following  search  paths to locate required
           shared libraries.


           5.  For  a  native linker, the contents of the environment variable

	But actually this does not occur because the NATIVE variable is
	never set in when we build ld.


	Unshar the below archive into a fresh directory.
	Run script ''.
	A working 'fred' binary should be produced. Currently we get
	a link error:

/usr/bin/ld: warning:, needed by /var/tmp/bug/subbar/, not found (try using -rpath or -rpath-link)
fred.o(.text+0x1e): In function `main':
: undefined reference to `foo' ./fred: not found

# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
# This archive contains:
#	fred.c
#	libbar.c
#	libfoo.c
echo x - fred.c
sed 's/^X//' >fred.c << 'END-of-fred.c'
Xint main (void) { return foo () + bar (); }
echo x - libbar.c
sed 's/^X//' >libbar.c << 'END-of-libbar.c'
Xint bar (void) { return foo (); }
echo x - libfoo.c
sed 's/^X//' >libfoo.c << 'END-of-libfoo.c'
Xint foo (void) { return 0; }
echo x -
sed 's/^X//' > << ''
Xmkdir subfoo subbar
Xgcc -c -fPIC libfoo.c
Xgcc -shared -o subfoo/ libfoo.o
Xgcc -c -fPIC libbar.c
Xgcc -shared -o subbar/ -L`pwd`/subfoo libbar.o -lfoo
Xexport LD_LIBRARY_PATH=`pwd`/subfoo:`pwd`/subbar
Xgcc -o fred fred.o -L`pwd`/subbar -lbar


RCS file: /usr/ncvs/src/gnu/usr.bin/binutils/ld/,v
retrieving revision 1.6
diff -u -r1.6
---	16 Jun 2004 07:09:37 -0000	1.6
+++	28 Apr 2006 16:01:15 -0000
@@ -50,7 +50,10 @@
 # Set some flags for the emultempl scripts.  USE_LIBPATH will
 # be set for any libpath-using emulation.
-      USE_LIBPATH=yes
+	if [ "x${host}" = "x${target}" ] ; then
+		NATIVE=yes
+	fi
 # Set the library search path, for libraries named by -lfoo.
 # If LIB_PATH is defined (e.g., by Makefile) and non-empty, it is used.


More information about the freebsd-bugs mailing list