在.zshrc中设置时未使用LD_LIBRARY_PATH

时间:2016-03-17 18:19:13

标签: linker shared-libraries zsh

在我的.zshrc文件中,我有以下一行:

export LD_LIBRARY_PATH='~/.local/lib'

我可以通过从命令行回显变量来确认变量已正确设置:

> echo $LD_LIBRARY_PATH
~/.local/lib

我有一个程序需要在本地lib目录中找到的库foo.so.1。直接从命令行运行失败:

> bar -v 123
bar: error when loading shared libraries: foo.so.1: cannot open shared object file: No such file or directory

但是,如果在运行命令之前手动设置LD_LIBRARY_PATH,一切正常:

> LD_LIBRARY_PATH=~/.local/lib bar -v 123
Success!

我的问题是:为什么在运行命令工作之前立即设置变量,而在.zshrc中设置它会失败?

1 个答案:

答案 0 :(得分:1)

Please ensure your env variable gets assigned the path with "~" being expanded to your home directory as such expansion will not take place when the variable is being read.

Your (revised) code uses single quotes. Those will prevent expansion from taking place.