Search code examples
matlabcshubuntu-14.04setenv

LD_LIBRARY_PATH: Undefined variable error


I am trying matlab script that depends on MCR. I have wrapper script that sets up environment variables for this MCR directory before executing the actual programme. The wrapper is as follows.

#!/bin/csh

set thisdir = `pwd`

# --- SET UP ENVIRONMENT VARIABLES ---
echo --- setting up environment variables ---
# presumed location of MATLAB Component Runtime (MCR) v7.14
# if the MCR is in a different location, edit the line below
set mcr_root = /home/foo/MATLAB_Component_Runtime
echo $mcr_root
setenv LD_LIBRARY_PATH $mcr_root/v81/runtime/glnxa64:$LD_LIBRARY_PATH
setenv LD_LIBRARY_PATH $mcr_root/v81/sys/os/glnxa64:$LD_LIBRARY_PATH
setenv LD_LIBRARY_PATH $mcr_root/v81/sys/java/jre/glnxa64/jre/lib/amd64/native_threads:$LD_LIBRARY_PATH
setenv LD_LIBRARY_PATH $mcr_root/v81/sys/java/jre/glnxa64/jre/lib/amd64/server:$LD_LIBRARY_PATH
setenv LD_LIBRARY_PATH $mcr_root/v81/sys/java/jre/glnxa64/jre/lib/amd64:$LD_LIBRARY_PATH
setenv XAPPLRESDIR $mcr_root/v81/X11/app-defaults
# (these may be set permanently by copying the above lines into your login script)

now when I run this script ./run_script I get this error -

LD_LIBRARY_PATH: Undefined variable.

I googled a lot and found some questions related, but none was usefull enough.

Any help is appreciated.


Solution

  • It's probably the case that LD_LIBRARY_PATH doesn't exist before you run your script. The first line in your script that sets LD_LIBRARY_PATH tries to append the existing path -- but the variable has not been defined.

    If you change the line in your script to

    setenv LD_LIBRARY_PATH $mcr_root/v81/runtime/glnxa64
    

    then it will work as you expect.