Hi this is my first post.
this question is about g++ version 4.3.3 and dynamically linked libraries.
if compile and run my program using:
Code:
g++ -o hellobeatles hellobeatles.o ../johnpaul/libjohnpaul.a ../georgeringo/libgeorgeringo.so
my executable runs just fine. ie ./hellobeatles outputs
Code:
$ ./hellobeatles
John, Paul, George, and Ringo
but if i run it using:
Code:
g++ -o hellobeatles hellobeatles.o -L../johnpaul -L../gerogeringo -ljohnpaul -lgeorgeringo
I get no errors & i recieve an executable but when i run it:
Code:
./hellobeatles returns:
./hellobeatles: error while loading shared libraries:
libgeorgeringo.so: cannot open shared object file:
No such file or directory
Here is my output for ldd hellobeatles:
For the executable that worked, ldd outputs:
Code:
$ ldd hellobeatles
linux-gate.so.1 => (0xb7f00000)
../georgeringo/libgeorgeringo.so (0xb7efb000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xb7dfd000)
libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xb7dd6000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb7dc7000)
libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7c64000)
/lib/ld-linux.so.2 (0xb7f01000)
The problem here is it is an absolute path. I can never move my executable without recreating the folder structure around it and move libgeorgeringo.so to the same relative location.
Here's what i want but the executable that doesn't work:
Code:
$ ldd hellobeatles
linux-gate.so.1 => (0xb8073000)
libgeorgeringo.so => not found
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xb7f73000)
libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xb7f4c000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb7f3d000)
libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7dda000)
/lib/ld-linux.so.2 (0xb8074000)
So I am not finding my libgeorgeringo.so library. This second method is what I prefer so i don't have to have my libFILENAME.so in a locked location relative to the executable.
(1) I tried adding the folder that holds the library to $PATH.
(2) I tried copying libgeorgeringo.so to /usr/bin
(3) I tried copying libgeorgeringo.so to the same folder as the executable
...
still no joy.
Why is g++ correctly finding the file if i specify it by name? But not when i try to have it dynamicaly linked. ie use -l option in g++ can anyone help me understand how to do this?
Please specify:
where to put my libFILENAME.so & how to have my executable program find the library. thank you so much for your help.