Subject: ld.so finds library, loses library
To: None <netbsd-help@NetBSD.org>
From: James K. Lowden <jklowden@schemamania.org>
List: netbsd-help
Date: 05/16/2007 17:06:49
I have an executable for which the runtime linker fails to find a shared
object that ldd admits is there.  I'm hoping someone here can point me in
the right direction.  I include the output of ldd, readelf, and the link
command line below.  

	$ uname -rs
	NetBSD 2.0_BETA
	$ .libs/bsqlodbc
	Shared object "libodbcinst.so.1" not found

$ ldd  .libs/bsqlodbc
.libs/bsqlodbc:
         -lodbcinst.1 => not found
         -lc.12 => /usr/lib/libc.so.12
         -ltdsodbc.0 => /usr/pkg/lib/libtdsodbc.so.0
         -lpthread.0 => /usr/lib/libpthread.so.0
         -lodbcinst.1 => /usr/local/lib/libodbcinst.so.1
         -lodbc.1 => /usr/local/lib/libodbc.so.1

lodbcinst.1 is reported 'not found' on line 1 and on line 5 as
/usr/local/lib/libodbcinst.so.1!  The files are there:

$ pwd && ls -l libodbcinst* | cut -b -10,51-
/usr/local/lib
-rwxr-xr-x libodbcinst.la
lrwxr-xr-x libodbcinst.so -> libodbcinst.so.1.0
lrwxr-xr-x libodbcinst.so.1 -> libodbcinst.so.1.0
-rwxr-xr-x libodbcinst.so.1.0

What does the RPATH look like, you might ask?  Good afaict:

$ readelf -d .libs/bsqlodbc | sed /RPATH/q

Dynamic segment at offset 0x3068 contains 22 entries:
  Tag        Type                         Name/Value
 0x00000001 (NEEDED)                     Shared library: [libtdsodbc.so.0]
 0x00000001 (NEEDED)                     Shared library:
[libodbcinst.so.1]
 0x00000001 (NEEDED)                     Shared library: [libodbc.so.1]
 0x00000001 (NEEDED)                     Shared library: [libpthread.so.0]
 0x00000001 (NEEDED)                     Shared library: [libc.so.12]
 0x0000000f (RPATH)                      Library rpath:
[/usr/pkg/lib:/usr/local/lib]

And here's the link line (generated by autoconf's configure script):

/bin/ksh \
	../../libtool \
	--tag=CC \
	--mode=link \
	gcc \
	-pthread \
	-g \
	-O2 \
	-L/usr/pkg/lib \
	-Wl,--rpath \
	-Wl,/usr/pkg/lib \
	-L/usr/local/lib \
	-o bsqlodbc \
	bsqlodbc.o \
	../odbc/libtdsodbc.la \
	../replacements/libreplacements.la \
	-lodbc \
gcc 	-g \
	-O2 \
	-Wl,--rpath \
	-Wl,/usr/pkg/lib \
	-o .libs/bsqlodbc \
	bsqlodbc.o \
	-pthread \
	-L/usr/pkg/lib \
	-L/usr/local/lib \
	../odbc/.libs/libtdsodbc.so \
	/usr/local/lib/libodbcinst.so \
	../replacements/.libs/libreplacements.a \
	/usr/local/lib/libodbc.so \
	-ldl \
	-lpthread \
	-Wl,--rpath \
	-Wl,/usr/local/lib
creating bsqlodbc

What am I doing wrong, apart from not exactly running -current?  

Thanks. 

--jkl