我不确定我的LD_LIBRARY_PATH
是否有效。
我在Ubuntu上安装了Qt5.2.1,并尝试使用sudo ./App1
从命令行执行应用程序。( App1需要sudo访问,因此我以这种方式执行)
具有*.so文件Qt5.2.1/Tools/QtCreator/lib/qtcreator
的文件夹在bashrc
文件中的LD_LIBRARY_PATH
中提供,但我得到了以下错误
./App1: error while loading shared libraries: libQt5Quick.so.5: cannot open shared object file: No such file or directory
当我将所有Qt文件从QtCreator复制到/usr/lib
时,应用程序工作正常。
有人能帮助我理解这个概念吗?为什么它不能从LD_LIBRARY_PATH
中获取库,而它却可以处理标准/usr/lib
路径中的Qt文件?
此外,在不将.so文件复制到/usr/lib
的情况下,应该做些什么来使其工作。
发布于 2014-06-14 18:56:05
默认情况下,您的用户的LD_LIBRARY_PATH
不会被sudo环境继承。根据sudoers手册(man sudoers
):
By default, the env_reset option is enabled. This causes commands to be
executed with a new, minimal environment. On AIX (and Linux systems
without PAM), the environment is initialized with the contents of the
/etc/environment file. The new environment contains the TERM, PATH,
HOME, MAIL, SHELL, LOGNAME, USER, USERNAME and SUDO_* variables in addi‐
tion to variables from the invoking process permitted by the env_check
and env_keep options. This is effectively a whitelist for environment
variables.
请注意,由于本节后面提到的原因,env_keep
不太可能为LD_LIBRARY_PATH
工作:
Note that the dynamic linker on most operating systems will remove vari‐
ables that can control dynamic linking from the environment of setuid
executables, including sudo. Depending on the operating system this may
include _RLD*, DYLD_*, LD_*, LDR_*, LIBPATH, SHLIB_PATH, and others.
These type of variables are removed from the environment before sudo even
begins execution and, as such, it is not possible for sudo to preserve
them.
您必须找到一种方法,使您的应用程序在没有sudo的情况下运行,或者将其所需的库安装到标准库位置之一。
https://askubuntu.com/questions/483320
复制相似问题