Forum > Unix

Loading .so Files in Program

<< < (2/6) > >>

marcov:
man ldconfig 

and environment variable LD_LOAD_LIBRARY_PATH

Leledumbo:
What if you execute:

--- Code: ---$ LD_LIBRARY_PATH=. ./yourapp
--- End code ---
Actually, under *nix shared libraries are meant to be loaded from static locations, e.g.: /usr[/local]/lib, but of course you can register another directories to be searched by the dynamic linker, which is what marco said.

garlar27:
Are you passing the full path to the library?

I have a proyect which uses dynlibs and runs in both OS windows and linux.


--- Code: ---     
LIBRARY_MYLIB_NAME := 'MyLib';
FMyLibHandle := dynlibs.LoadLibrary(TheLibrariesLocation + LIBRARY_MYLIB_NAME);

--- End code ---

LoadLibrary adds prefix "lib" if on Linux and add the appropiate extension (".so" on Linux and ".dll" on windows). And don't forget to use THE FULL PATHWAY. Otherwise it won't find the library.

PatrickS:
Hello, sorry for my late response.

today I tried to load the libc.so in lazarus eith two differeten locations.


--- Code: ---Hndl1:=LoadLibrary('libc.so');
S:=GetLoadErrorStr;
Writeln(s);             //   S = 'usr/lib/arm-linux-gnueabihf/lib6.so: Ung├╝ltiger ELF-Header'

Hndl2:=LoadLibrary('/root/Desktop/libc.so'); // here is a copy of libc.so
S:=GetLoadErrorStr;
Writeln(s); // same like before


Hndl2:=LoadLibrary('/root/Desktop/own_lib.so'); // self created lib in lazarus
S:=GetLoadErrorStr;
Writeln(s);             //   S = 'root/Desktop/own_lib.so: Can not open the Shared-Object-File : File or Directory not found'

--- End code ---

The file and the directory exists, see atttachment.

garlar27:
Do you have permissions to read / write in that folder? My gess is you don't or you shouldn't.
I don't remember if the library needs execution permissions.

The way we use it is like this:

--- Code: ---LIBRARY_MYLIB_NAME := 'libMyLib';// We use the lib prefix because we want to have the "same" file name on Windows and Linux. Without extension thus is more cross-platform.
TheLibrariesLocation := Application.Location;// = '/usr/UserName/MyApplication/'
FMyLibHandle := dynlibs.LoadLibrary(TheLibrariesLocation + LIBRARY_MYLIB_NAME);

--- End code ---

ATM I'm not on Linux so I can't try your code.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version