I am trying to load shared library, but I dont have its .so file in directory loader look for, So I want to set a environment dir.
$ ls # (current dir is bindir)
foo.c foo.h libfoo.so exe
$ path_to_dir=/home/user/bindir
$ $path_to_dir ./exe "bla bla"
bash: /home/user/bindir: Is a directory
This may be trivial, But i do not usually run program with modified environment variables, so how to set it?
If I tried to $ export path_to_dir
, and run it:
$ ./exe "bla bla"
./_exe: error while loading shared libraries: libfoo.so: cannot open shared object file: No such file or directory
So how to modify the environment variable of my dir?
EDIT:
according to this tutorial: youtube library tutorial, the linker cannot see the library (libfoo.so
, in my case) file, becuase it does not search my current dirctory. The standard libraries ld
uses, I get by this:
$ld --verbose | grep -i search_dir | awk '{print $1}' RS=';'
SEARCH_DIR("=/usr/local/lib/x86_64-linux-gnu")
SEARCH_DIR("=/lib/x86_64-linux-gnu")
SEARCH_DIR("=/usr/lib/x86_64-linux-gnu")
SEARCH_DIR("=/usr/lib/x86_64-linux-gnu64")
SEARCH_DIR("=/usr/local/lib64")
SEARCH_DIR("=/lib64")
SEARCH_DIR("=/usr/lib64")
SEARCH_DIR("=/usr/local/lib")
SEARCH_DIR("=/lib")
SEARCH_DIR("=/usr/lib")
SEARCH_DIR("=/usr/x86_64-linux-gnu/lib64")
SEARCH_DIR("=/usr/x86_64-linux-gnu/lib")
So the the the relation between the variable $path_to_dir
and those above is, that I want to make my directory visible to ld
by making the $path_to_dir
as environment variable (also tried export
, but as you see - to no avail). So how to make visible my dir to ld
in order to "see" my library and link it with the position-independet program?