g++ dynamically linked library not being found
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 Code:
$ ./hellobeatles Code:
g++ -o hellobeatles hellobeatles.o -L../johnpaul -L../gerogeringo -ljohnpaul -lgeorgeringo Code:
./hellobeatles returns: For the executable that worked, ldd outputs: Code:
$ ldd hellobeatles Here's what i want but the executable that doesn't work: Code:
$ ldd hellobeatles 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. |
There is a difference between the path used to access the library definitions at link time, and the path used to dynamically load the library at runtime.
The -L flag you give to gcc gives it a path to search for static libraries and for dynamic libraries for use by the linker, but this does not affect where the executable will search for dynamic libraries (typically only /lib and /usr/lib, not /usr/bin). There are several ways of providing a runtime library path. An older method was to use the environment variable LD_LIBRARY_PATH. Now, if you want to provide global access to the dynamic libraries, you would add their path to one of the /etc/ld.so.conf.d/ files, and run ldconfig (see 'man ldconfig'). Or if you just want it for a single application you can incorporate it into the executable by using the linker flag '-R /path/to/library'. |
neonsignal, Thank you this is exactly the information I was after. as you can tell I'm no guru, but you're helping me get there.
Problem solved! |
Moved: This thread is more suitable in <Programming> and has been moved accordingly to help your thread/question get the exposure it deserves.
|
problem using -R flag
Ok I had been adding the .so files to my /usr/local/lib, but I want to know how to use the '-R /path/to/library' type execution.
Here's what I've tried so far: Code:
./hellobeatles -R ../georgeringo/libgeorgeringo.so Code:
./hellobeatles '-R ../georgeringo/libgeorgeringo.so' Code:
./hellobeatles '-R ../georgeringo/' Code:
./hellobeatles: error while loading shared libraries: libgeorgeringo.so: cannot open shared object file: No such file or directory Thank you for your help. |
Quote:
To do something like that at load time, you must modify the LD_LIBRARY_PATH environment variable. |
ok thank you.
|
All times are GMT -5. The time now is 06:08 PM. |