[so] Legare biblioteci

Razvan Deaconescu razvan.deaconescu at cs.pub.ro
Sun Mar 14 20:36:38 EET 2010


On Sun, 2010-03-14 at 20:13 +0200, Andrei Soare wrote:
> Salut,
> 
> In primul rand multumesc pentru raspunsuri si imi cer scuze ca nu am
> apucat sa testez si sa va raspund pana acum.
> 
> Am obeservat si eu ca implicit se ia biblioteca dinamica.
> 
> Totusi, am observat ca nu merge -lexemplu1.{a,so} imi spune
> "/usr/bin/ld: cannot find -lexemplu1.so"

Nu poti sa pui extensie la o biblioteca atunci cand folosesti -l. Poti
fie numele complet _fara_ -l, fie numele incomplet (_fara_ prefixul lib
si _fara_ extensie) dar _cu_ -l, ca aici:

---
razvan at valhalla:/tmp$ gcc -Wall -c add.c 
razvan at valhalla:/tmp$ gcc -Wall -c main.c
razvan at valhalla:/tmp$ gcc -shared -fPIC -o libtest.so add.o
razvan at valhalla:/tmp$ gcc -o exec main.o libtest.so 
razvan at valhalla:/tmp$ ./exec 
./exec: error while loading shared libraries: libtest.so: cannot open
shared object file: No such file or directory
razvan at valhalla:/tmp$ LD_LIBRARY_PATH=. ./exec 
sum(1, 2) = 3
razvan at valhalla:/tmp$ rm exec
razvan at valhalla:/tmp$ gcc -o exec main.o -ltest -L.
razvan at valhalla:/tmp$ LD_LIBRARY_PATH=. ./exec 
sum(1, 2) = 3
---

Razvan



More information about the so mailing list