Load .so shared library file from a folder

I am going to run the following .pl file.

:- load_foreign_library(testenv).

I have created the testenv.so file from C. This whole process runs fine when I put the testenv.so file in the current running folder. However, I need to put the .so file in a given folder, and run the prolog from another folder. So I need to a way to point the prolog to the correct location.
I tried LD_LIBRARY_PATH env variable, and also “file_search_path” (the latter one I am not sure if I used it correctly). nothing works so far.

How can I make it work? and another question, is there a C interface api function that I can use to load the .so file, instead of using the prolog directive?


Normally, extend the file search path foreign as in

user:file_search_path(foreign, ...).

Where ... is a specification of the directory, which is either based on some alias as Alias(Subdir) or an absolute path (not recommended) or a relative path. Then use

:- load_foreign_library(foreign(testenv)).

Thanks Jan. It works perfectly!