我不确定我的是否LD_LIBRARY_PATH
在工作。
我在 Ubuntu 上安装了 Qt5.2.1,并尝试使用从命令行执行应用程序sudo ./App1
。(App1 需要 sudo 访问权限,因此我以这种方式执行)
在文件Qt5.2.1/Tools/QtCreator/lib/qtcreator
中提供了包含 *.so 文件的文件夹,但是我收到以下错误LD_LIBRARY_PATH
bashrc
./App1: error while loading shared libraries: libQt5Quick.so.5: cannot open shared object file: No such file or directory
当我将所有 Qt so 文件从 QtCreator 复制到 时/usr/lib
,应用程序就可以运行了。
有人能帮助我理解这个概念吗,为什么它不能从中获取库,而它可以与标准路径LD_LIBRARY_PATH
中的 Qt 文件一起使用/usr/lib
此外,如果不将 .so 文件复制到 ,应该怎么做才能使其工作/usr/lib
。
答案1
默认情况下,您的用户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 的情况下运行,或者在标准库位置之一安装它所需的库。