我有一些使用一些共享库的代码(gcc 上的 c 代码)。编译时,我必须使用 -I 和 -L 显式定义包含和库目录,因为它们不在标准位置。当我尝试运行代码时,出现以下错误:
./sync_test
./sync_test: error while loading shared libraries: libsync.so: cannot open shared object file: No such file or directory
但是,执行以下操作,一切正常:
export LD_LIBRARY_PATH="/path/to/library/"
./sync_test
现在,奇怪的是,这只能工作一次。如果我再次尝试运行sync_test,我会得到同样的错误,除非我先运行导出命令。我尝试将以下内容添加到我的 .bashrc 中,但没有任何区别:
LD_LIBRARY_PATH="/path/to/library/"