Forum > Unix

Loading .so Files in Program

<< < (2/6) > >>

man ldconfig 

and environment variable LD_LOAD_LIBRARY_PATH

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.

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: ---     
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.

Hello, sorry for my late response.

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

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

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

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

--- End code ---

The file and the directory exists, see atttachment.

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.


[0] Message Index

[#] Next page

[*] Previous page

Go to full version