ld finds some libraries, but not others (REVISED)
Jonathan Ryshpan
jonrysh at pacbell.net
Thu Dec 15 08:31:26 UTC 2011
A build is failing with the error cannot find <library> for libraries
that are, in fact present on the system.
I made a very simple test bed, consisting of the empty file conftest.c,
which I attempt to compile and link with various libraries. All the
libraries are in /usr/lib64. Sometimes the compilation fails with
undefined reference to `main'
which is what I would expect, but often it fails with
cannot find -l<whatever>
I have no idea what's happening. Can anyone explain?
Here's an example of what's going on. This is a listing of some files
in /usr/lib64:
$ ll libICE.so* libgd.so* libkate.so* libkblog.so.*
lrwxrwxrwx. 1 root root 15 Nov 9 18:28 libICE.so -> libICE.so.6.3.0*
lrwxrwxrwx. 1 root root 15 Nov 9 08:02 libICE.so.6 -> libICE.so.6.3.0*
-rwxr-xr-x. 1 root root 98328 Jun 21 09:37 libICE.so.6.3.0*
lrwxrwxrwx. 1 root root 14 Nov 9 08:14 libgd.so.2 -> libgd.so.2.0.0*
-rwxr-xr-x. 1 root root 278048 Oct 26 20:15 libgd.so.2.0.0*
lrwxrwxrwx. 1 root root 16 Nov 9 08:06 libkate.so.1 -> libkate.so.1.2.1*
-rwxr-xr-x. 1 root root 75640 Mar 7 2011 libkate.so.1.2.1*
lrwxrwxrwx. 1 root root 17 Nov 13 09:03 libkblog.so.4 -> libkblog.so.4.7.0*
-rwxr-xr-x. 1 root root 312960 Nov 4 10:05 libkblog.so.4.7.0*
And here's a attempt to compile the dummy linking to them:
$ gcc -o conftest -g -O2 conftest.c -lICE
/usr/lib/gcc/x86_64-redhat-linux/4.6.2/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
1034 wview-5.19.0 $ gcc -o conftest -g -O2 conftest.c -lgd
/usr/bin/ld: cannot find -lgd
collect2: ld returned 1 exit status
1035 wview-5.19.0 $ gcc -o conftest -g -O2 conftest.c -lkate
/usr/bin/ld: cannot find -lkate
collect2: ld returned 1 exit status
1036 wview-5.19.0 $ gcc -o conftest -g -O2 conftest.c -lkblog
/usr/lib/gcc/x86_64-redhat-linux/4.6.2/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
System information:
Fedora-16 with all updates running on 4 cpu x86_64 hardware
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.6.2/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.6.2 20111027 (Red Hat 4.6.2-1) (GCC)
$ ld -v
GNU ld version 2.21.53.0.1-2.fc16 20110716
More information about the users
mailing list