Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 20 Oct 2000 13:58:40 -0400
From:      Joe Diehl <jdiehl@genuity.net>
To:        freebsd-questions@freebsd.org
Subject:   linking oddness
Message-ID:  <20001020135840.P11549@genuity.net>

next in thread | raw e-mail | index | archive | help
I was wondering if someone can help me out here, seeing as I'm now rather lost.
I'm having problems with linking libraries that I install in /usr/local/lib.

For instance:

$ LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/usr/X11R6/lib:/lib
$ export LD_LIBRARY_PATH
$ gcc -o test test.o -ljpeg
/usr/libexec/elf/ld: cannot find -ljpeg
$ gcc -o test test.o -L/usr/local/lib -ljpeg
$ ldd test
test:
        libjpeg.so.62 => /usr/local/lib/libjpeg.so.62 (0x28064000)
        libc.so.4 => /usr/lib/libc.so.4 (0x28082000)


jdiehl@eros:~$ ls /usr/local/lib/libjpeg*
/usr/local/lib/libjpeg.a        /usr/local/lib/libjpeg.so
/usr/local/lib/libjpeg.la       /usr/local/lib/libjpeg.so.62
/usr/local/lib/libjpeg.lai      /usr/local/lib/libjpeg.so.9


I'm running FreeBSD 4.1.1-RELEASE

I havn't fiddled with gcc/binutils at all:

  jdiehl@eros:~$ gcc -v
  Using builtin specs.
  gcc version 2.95.2 19991024 (release)

  jdiehl@eros:~$ ld -v
  GNU ld version 2.10.0 (with BFD 2.10.0)

Because of these problems I've tried fiddling with /etc/ld{,-elf}.so.conf:

  jdiehl@eros:~$ cat /etc/ld-elf.so.conf
  /usr/lib
  /usr/lib/compat
  /usr/X11R6/lib
  /usr/local/lib

  jdiehl@eros:~$ cat /etc/ld.so.conf
  /usr/lib/compat/aout
  /usr/X11R6/lib/aout
  /usr/local/lib/aout
  /usr/lib/compath
  /usr/X11R6/lib
  /usr/local/lib

  I did do an `ldconfig -aout; ldconfig -elf` 

Note that this isn't limited to libjpeg:

  jdiehl@eros:~$ gcc -o test test.o -ltiff
  /usr/libexec/elf/ld: cannot find -ltiff

  jdiehl@eros:~$ gcc -o test test.o -lXau 
  /usr/libexec/elf/ld: cannot find -lXau

  jdiehl@eros:~$ gcc -o test test.o -lX11
  /usr/libexec/elf/ld: cannot find -lX11

Now for some fun with truss:

  $ truss ld -o test test.o -lc -ljpeg 2>&1 | grep libjpeg
  open("/usr/lib/libjpeg.so",0,0666)           ERR#2 'No such file or directory'
  open("/usr/lib/libjpeg.a",0,0666)            ERR#2 'No such file or directory'

  $ truss ld -o test test.o -lc -ljpeg 2>&1 | grep libc\.
  access("/usr/local/lib/libc.so.4",0)         ERR#2 'No such file or directory'
  access("/usr/lib/libc.so.4",0)               = 0 (0x0)
  open("/usr/lib/libc.so.4",0,027757774730)    = 3 (0x3)
  open("/usr/lib/libc.so",0,0666)              = 5 (0x5)


Right so.. It'll look for libc in /usr/local/lib like my LD_LIBRARY_PATH asks;
however, it ignores my LD_LIBRARY_PATH for libjpeg?  I notice that FreeBSD
uses ld.so.conf for a.out and ld-elf.so.conf for elf binaries, is there 
something differant I need for elf linking besides LD_LIBRARY_PATH?

From the ld(1) manpage:

       -Lsearchdir
              This  command  adds  path  searchdir to the list of
              paths that ld will search  for  archive  libraries.
              You may use this option any number of times.

              The  default  set  of paths searched (without being
              specified with -L) depends on what  emulation  mode
              ld  is  using, and in some cases also on how it was
              configured.    The paths can also be specified in a
              link script with the SEARCH_DIR command.

Ok so I'm going to try this, though I'm not sure about exactly sure what format
is expected in SEARCH_DIR:

  $ SEARCH_DIR="/usr/local/lib:/usr/lib:/usr/X11R6/lib"
  $ export SEARCH_DIR
  $ gcc -o test test.o -ljpeg
  /usr/libexec/elf/ld: cannot find -ljpeg

  $ SEARCH_DIR="-L/usr/local/lib" 
  $ export SEARCH_DIR
  $ gcc -o test test.o -ljpeg
  /usr/libexec/elf/ld: cannot find -ljpeg

Any thoughts?  

I'm not on this list, so please cc: any replies to me.  

Thanks :)

-- Joe Diehl (jdiehl@genuity.net)


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20001020135840.P11549>