【发布时间】:2019-08-21 00:25:21
【问题描述】:
我正在尝试在没有 root 访问权限的服务器上编译和运行 C++ 程序。我在链接boost_iostreams 库时遇到问题。
我可以通过使用-L标志指向boost安装目录成功编译我的程序:
g++ -I path/to/boost/build/include -o out prog1.cpp prog2.cpp -L path/to/boost/build/lib -lboost_iostreams
但是,如果我以./out 身份运行程序,则会收到错误error while loading shared libraries: libboost_iostreams.so.1.67.0: cannot open shared object file: No such file or directory,因为链接器无法找到libboost_iostreams.so.1.67.0(确实存在于path/to/boost/build/lib 下)
感谢this 的回答,我能够明确指定LD_LIBRARY_PATH 并将程序运行为
LD_LIBRARY_PATH="path/to/boost/build/lib" ./out.
因为我不是root,所以我也不能运行ldconfig。我想知道是否有一种方法可以加载动态库,而无需在运行程序且没有 root 访问权限时添加前缀 LD_LIBRARY_PATH。
【问题讨论】: