Setting the LD_LIBRARY_PATH environment variable to load the shared library at runtime (g ++)

I am having two problems related to the same problem:

  • I have a shared object stored in `pwd` / lib, and while the executable that uses it compiles successfully (using the -l and -L switches), at runtime it gives me sadness. If I try to run LD_LIBRARY_PATH=/my/absolute/path/to/library/directory ./testit works fine. But if I export the LD_LIBRARY_PATH = / my / absolute / path / to / library / directory and do it ./test, it says that it cannot find the shared library. However, if I do LD_LIBRARY_PATH=$LD_LIBRARY_PATH ./testagain, it works great !! Any ideas on what I'm doing wrong?

  • The second problem is related to the export of the EN_LIBRARY_PATH variable. If I open the terminal and export LD_LIBRARY_PATH=/path/to/stufftype and then enter echo $LD_LIBRARY_PATH, the variable is correct. However, if I write a script containing the export command by simply running it, it does not update the variable, instead I need to run source install.shto actually save the variable. What is the best solution for this?

Thank you for your time!

+5
source share
2 answers

First answer the second question :

sourceexecutes a script inside the current shell, ./install.shopens and executes it in another shell. http://www.unix.com/unix-dummies-questions-answers/537-difference-between-source-exec-script.html

Now for your first question:

LD_LIBRARY_PATH=$LD_LIBRARY_PATH ./test LD_LIBRARY_PATH ( ./test). , , ./test. , export LD_LIBRARY_PATH=... ~/.bashrc

+5

, -L CFLAGS , LD_RUN_PATH . : export CFLAGS = -L/opt/tool/lib

+1

All Articles