Hallo, Am Tue, 17 Feb 2004, Dieter Kluenter schrieb:
Natürlich können, und sollten auch, alle selbst erstellten Biliotheken und Headerdateien, die nicht vom System installiert wurden, in /usr/local installiert werden. Der GNU Linker '/usr/bin/ld', also das Tool, das die Bibliotheken einbindet, wird über /etc/ld.config konfiguriert.
NEIN. Ueber /etc/ld.so.conf wird der dynamische lader /lib/ld-linux.so (alias /lib/ld.so), der _zur Laufzeit_ die libs laedt, konfiguriert.
Mit '/sbin/ldconfig' werden alle in ld.config aufgeführten Pfade abgeklappert und alle vorhandenen Dateien in einer Hashdatei '/etc/ld.so.cache' aufgelistet.
Das stimmt -- aber fuer ld-linux!
Bei einer Kompilation wird dann alle im Cache vorhanden shared Libraries bereitgestellt.
Nein. Einfaches Beispiel: ==== dh@slarty[5]: ~ (0)$ cd /tmp/test dh@slarty[5]: /tmp/test (0)$ PS1="\$?$ " 0$ grep X11 /etc/ld.so.conf | head -1 /usr/X11R6/lib 0$ echo 'int main(void){return 0;}' > test_ld.c 0$ gcc -lX11 -o test_ld test_ld.c /usr/bin/ld: cannot find -lX11 collect2: ld returned 1 exit status 1$ ls -l test_ld ls: test_ld: No such file or directory 1$ gcc -L/usr/X11R6/lib -lX11 -o test_ld test_ld.c 0$ ls -l test_ld -rwxr-xr-x 1 dh dh 11675 Feb 18 04:37 test_ld 0$ ldd ./test_ld libX11.so.6 => /usr/X11R6/lib/libX11.so.6 (0x40028000) libc.so.6 => /lib/libc.so.6 (0x400d0000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000) 0$ ./test_ld 42$ ==== Der _gcc_ (genauer dessen ld-wrapper collect2) bzw. der linker (/usr/bin/ld) haben einen Suchpfad, der default-maessig /lib, /usr/lib, /usr/local/lib und /usr/$arch/lib/ enthaelt. ==== 42$ rm test_ld 0$ gcc -c -o test_ld.o test_ld.c 0$ ld --verbose -lX11 -o test_ld test_ld.o /usr/lib/crt1.o attempt to open /usr/lib/libX11.so failed attempt to open /usr/lib/libX11.a failed attempt to open /lib/libX11.so failed attempt to open /lib/libX11.a failed attempt to open /usr/lib/libX11.so failed attempt to open /usr/lib/libX11.a failed attempt to open /usr/local/lib/libX11.so failed attempt to open /usr/local/lib/libX11.a failed attempt to open /usr/i686-pc-linux/lib/libX11.so failed attempt to open /usr/i686-pc-linux/lib/libX11.a failed ld: cannot find -lX11 1$ ld --verbose -L/usr/X11R6/lib -lX11 -o test_ld test_ld.o /usr/lib/crt1.o attempt to open /usr/X11R6/lib/libX11.so succeeded -lX11 (/usr/X11R6/lib/libX11.so) attempt to open test_ld.o succeeded test_ld.o attempt to open /usr/lib/crt1.o succeeded /usr/lib/crt1.o libc.so.6 needed by /usr/X11R6/lib/libX11.so found libc.so.6 at /lib/libc.so.6 ld-linux.so.2 needed by /lib/libc.so.6 found ld-linux.so.2 at /lib/ld-linux.so.2 0$ ==== Wie man hier sieht, muss man (per -L) das Verzeichnis explizit angeben wenn die lib nicht in einem der 3 Standardverzeichnisse liegt. Und man sieht schoen, wie ld nach der lib sucht. Achso, bevor sich jemand wundert: das zuletzt erzeugte ist _NICHT_ ausfuehrbar, da fehlen noch ein paar Sachen, die lustige Effekte zeigen: ==== 0$ ls -l ./test_ld -rwxr-xr-x 1 dh dh 9741 Feb 18 04:45 ./test_ld 0$ file ./test_ld ./test_ld: ELF 32-bit LSB executable, Intel 80386, version 1, dynamically linked (uses shared libs), not stripped 0$ ldd ./test_ld /usr/bin/ldd: ./test_ld: No such file or directory 1$ ./test_ld bash: ./test_ld: No such file or directory 127$ rm ./test_ld 0$ gcc -v -L/usr/X11R6/lib -lX11 -o test_ld test_ld.o Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/pgcc-2.95.3/specs gcc version pgcc-2.95.3 19991024 (AMD-20000925-1) /usr/local/lib/gcc-lib/i686-pc-linux-gnu/pgcc-2.95.3/collect2 -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o test_ld /usr/lib/crt1.o /usr/lib/crti.o /usr/local/lib/gcc-lib/i686-pc-linux-gnu/pgcc-2.95.3/crtbegin.o -L/usr/X11R6/lib -L/usr/local/lib/gcc-lib/i686-pc-linux-gnu/pgcc-2.95.3 -L/usr/local/lib -lX11 test_ld.o -lgcc -lc -lgcc /usr/local/lib/gcc-lib/i686-pc-linux-gnu/pgcc-2.95.3/crtend.o /usr/lib/crtn.o 0$ ldd ./test_ld libX11.so.6 => /usr/X11R6/lib/libX11.so.6 (0x40028000) libc.so.6 => /lib/libc.so.6 (0x400d0000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000) 0$ ./test_ld 42$ ==== *grins* Achso, dass im Quelltext nicht auf die libX11 zugegriffen wird ist hier irrelevant. Ein 'unresolved symbol' kommt erst spaeter: ==== 42$ cp ~/src/misc/xnumlock.c ./test_ld.c 0$ gcc -lX11 -o test_ld test_ld.c /usr/bin/ld: cannot find -lX11 collect2: ld returned 1 exit status 1$ gcc -L/usr/X11R6/lib -o test_ld test_ld.c /tmp/ccITWt5s.o: In function `main': /tmp/ccITWt5s.o(.text+0xc): undefined reference to `XOpenDisplay' [..] collect2: ld returned 1 exit status 1$ gcc -L/usr/X11R6/lib -lX11 -o test_ld test_ld.c /tmp/ccWFCOSM.o: In function `main': /tmp/ccWFCOSM.o(.text+0x48): undefined reference to `XTestFakeKeyEvent' [..] collect2: ld returned 1 exit status 1$ gcc -L/usr/X11R6/lib -lX11 -lXtst -o test_ld test_ld.c 0$ ldd ./test_ld libX11.so.6 => /usr/X11R6/lib/libX11.so.6 (0x40028000) libXtst.so.6 => /usr/X11R6/lib/libXtst.so.6 (0x400d0000) libc.so.6 => /lib/libc.so.6 (0x400d6000) libXext.so.6 => /usr/X11R6/lib/libXext.so.6 (0x401b8000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000 0$ ==== So, und der Vollstaendigkeit halber auch noch, was ld-linux, der dynamische Linker, dann unter anderem so macht: ==== 0$ LD_LIBRARY_PATH="" LANG="C" strace -eopen ./test_ld open("/etc/ld.so.preload", O_RDONLY) = -1 ENOENT (No such file or directory) open("/etc/ld.so.cache", O_RDONLY) = 3 open("/usr/X11R6/lib/libX11.so.6", O_RDONLY) = 3 open("/usr/X11R6/lib/libXtst.so.6", O_RDONLY) = 3 open("/lib/libc.so.6", O_RDONLY) = 3 open("/usr/X11R6/lib/libXext.so.6", O_RDONLY) = 3 open("/home/dh/.Xauthority", O_RDONLY) = 4 open("/usr/X11R6/lib/X11/locale/locale.alias", O_RDONLY) = 4 open("/usr/X11R6/lib/X11/locale/locale.dir", O_RDONLY) = 4 open("/usr/X11R6/lib/X11/locale/C/XLC_LOCALE", O_RDONLY) = 4 ==== Alle Klarheiten beseitigt? F'up2: suse-programming -dnh -- 278: Shareware-Link Folge des Patents der British Telekom auf Hyperlinks: US-A-4,873,662 (Raphael H. Becker)