简体   繁体   English

LD_LIBRARY_PATH在bash脚本中失败

[英]LD_LIBRARY_PATH fails in bash script

I have a bash script that runs this line of code: 我有一个运行以下代码行的bash脚本:

LD_LIBRARY_PATH=/tools/cluster/6.2/openbabel/2.3.2/lib ./xattr infile.txt outfile.txt

If I were to call this line directly from the shell, it works fine. 如果我直接从shell调用此行,则可以正常工作。 However if I run it in the bash script I get this error: 但是,如果我在bash脚本中运行它,则会出现此错误:

update.sh: line 45: LD_LIBRARY_PATH=/tools/cluster/6.2/openbabel/2.3.2/lib: No such file or directory

Why doesn't LD_LIBRARY_PATH work when it's set in a bash script? 在bash脚本中设置LD_LIBRARY_PATH为何不起作用?

Here's more of the code around line 45: 以下是第45行的更多代码:

BASE_DIR="/volatile/huanlab/bold/kendal/bioinformatics_database/tmp"
COMP_DIR="$BASE_DIR/compound"

# move to the current directory where xattr.cpp and other files are
cd /users/kharland/software/programs/BioDB-update/dev

# Compile xattr ('make xattr' is the same command I call from the shell
# to compile this program when this program actually works).
make xattr

# loop over each .sdf file in COMP_DIR
for INF in $(ls $COMP_DIR | grep sdf)
do
    babel -isdf $COMP_DIR/$INF -ocan $SMILES_DIR/$INF.csv
    LD_LIBRARY_PATH=/tools/cluster/6.2/openbabel/2.3.2/lib ./xattr $COMP_DIR/$INF $COMP_DIR/$COMP_FILE
done

The contents before these lines are just comments 这些行之前的内容仅是注释

edit 编辑

In My makefile, I am compiling with these options 在我的makefile中,我正在使用这些选项进行编译

LDLIBS=-lm -ldl -lz -lopenbabel
LDFLAGS=-Wl,-rpath,/tools/cluster/6.2/openbabel/2.3.2/lib:/tools/cluster/system/pkg/openbabel/openbabel-2.3.2/build/lib,-L/tools/cluster/6.2/openbabel/2.3.2/lib

and running ldd xattr shows that the libraries are indeed linked, so the program executes as expected when invoked from the shell. 运行ldd xattr表示库确实已链接,因此从shell调用时程序按预期执行。 The only issue is with the bash script. 唯一的问题是bash脚本。 If I remove the LD_LIBRARY_PATH option from the bash script I get an issue where the shared libraries for openbabel aren't found even though ldd shows that xattr knows where the libs are. 如果我从bash脚本中删除了LD_LIBRARY_PATH选项,则会遇到一个问题,即即使ldd显示xattr知道库在哪里,也无法找到openbabel的共享库。 That's why I have LD_LIBRARY_PATH added in the bash script, I'm attempting to use it as a workaround 这就是为什么我在bash脚本中添加了LD_LIBRARY_PATH的原因,我试图将其用作解决方法

edit 编辑
(corrected mistake: swapped 'libraries' with 'my code' below) (had wrong file system name below) (已更正的错误:将下面的“库”与“我的代码”交换了) 下面的 文件系统名称错误)

Something just occurred to me. 我刚发生了什么事。 My source code is in the /users file system. 我的源代码在/users文件系统中。 If my libraries are on a different, mounted file system, would bash have trouble finding these documents? 如果我的库位于其他已挂载的文件系统上,bash是否会在查找这些文档时遇到麻烦?

Setting environment variables does work in bash scripts. 设置环境变量确实可以在bash脚本中使用。

Try this: 尝试这个:

#!/bin/bash
VAR1=VALUE1 env

...run that script, and you'll see output that includes VAR1 and its value. ...运行该脚本,您将看到包含VAR1及其值的输出。

Generally speaking, this also works with LD_LIBRARY_PATH : 一般来说,这也适用于LD_LIBRARY_PATH

#!/bin/bash
tempdir=$(mktemp -t -d testdir.XXXXXX)
LD_LIBRARY_PATH=$tempdir env
rm -rf "$tempdir"

If you can generate a minimal reproducer in which this doesn't occur, that would be helpful and appreciated. 如果您可以生成一个最小的复制器,而不会发生这种情况,那将是有帮助和赞赏的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM