I'm testing a small program my colleague wrote. To slightly improve the program setup, I fixed a line but it doesn't work. Here is the phenomenon. In directory ~/vect_run, there are two scripts go.sh and SourceMe.sh (I very much simplified it for this post).
go.sh:
#!/bin/bash
cd run
source ../SourceMe.sh
baremetal
SourceMe.sh:
#!/bin/bash
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${PWD%/*}
echo "LD_LIBRARY_PATH="$LD_LIBRARY_PATH
The baremetal
program is in ~/vect_add/run directory and during the run, it needs test.so file which is in ~/vect_add directory. The go.sh sources SourceMe.sh to set the environment LD_LIBRARY_PATH and it calls the program baremetal
. By the echo command in the SourceMe.sh I can see the LD_LIBRARY_PATH is set correct (in contains ~/vect_add directory). But the baremetal
program complains it can't find test.so. Even at this failed stage, if I echo $LD_LIBRARY_PATH it is correctly set. If I explicitly do export LD_LIBRARY=...
(with the same value), baremetal
program runs ok. I tried LD_LIBRARY_PATH=...
without export
. What is wrong in the script??
Here is how it looks (simplified for this post)
ckim@ckim-ubuntu:~/vect_add$ go.sh
LD_LIBRARY_PATH=/usr/local/lib:/home/ckim/vect_add
Load test.so Failed
test.so: cannot open shared object file: No such file or directory
ckim@ckim-ubuntu:export LD_LIBRARY_PATH=/usr/local/lib:/home/ckim/vect_add
Found test.so. using dynamic library test.so..
Program ran ok!
ADD 1 : Since exporting a variable is in effect in subshells, I tried removing the export
in LD_LIBRARY_PATH. Didn't work.
ADD 2 : Also tried removing #!/bin/bash in the SourceMe.sh (because it creates a sub-shell, and I want the variable to set set in the current shell). Bit didn't work either.
ADD 3 : I tried sourcing SourceMe.sh separately and running baremetal under run. I didn't work either.
ADD 4
: I have made a new simplest reproducible question, please see : setting LD_LIBRARY_PATH doesn't have any effect in bash, why?