0

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?

autistic456
  • 183
  • 1
  • 10
  • How is `path_to_dir` variable related to finding the `.so` file? – KamilCuk Jun 05 '20 at 15:03
  • @KamilCuk the program loader is looking for new libreries and cannot find mine. The standard dirs, the loader looks are e.g. `/usr/local/lib/x86_64-linux-gnu, etc`. So I want to modify the environment, so loader can See my library and use it. – autistic456 Jun 05 '20 at 18:05
  • @KamilCuk see my edits – autistic456 Jun 05 '20 at 18:11
  • Cool, but why did you name the variable `path_to_dir`? Why did you think that a variable with that particular name would affect linker? Read [man ld-linux](https://linux.die.net/man/8/ld-linux) – KamilCuk Jun 05 '20 at 18:40
  • Does this answer your question? [How to modify a LD\_LIBRARY\_PATH environment variable?](https://stackoverflow.com/questions/46175203/how-to-modify-a-ld-library-path-environment-variable) – omajid Jun 06 '20 at 21:48

0 Answers0