LD_LIBRARY_PATH尝试运行Qt应用程序时失败 [英] LD_LIBRARY_PATH failing while trying to run Qt app
问题描述
我想在Linux上使用基于indt动态库的Qt 5应用程序.总之,脚本会将可执行文件和其他相关文件(包括lib
文件夹中的所有必需.so文件)复制到所需的目标位置,并且调用gksudo
的脚本将作为应用程序的调用者.
I want to run a Qt 5 based application usind dynamic libraries on Linux. In summary, a script will copy the executable and other relevant files, including all required .so inside a lib
folder, to the desired destination and a script calling gksudo
will work as caller to the app.
到现在为止,一切正常,直到我调用可执行脚本:该应用程序未运行.当我要求使用sudo
运行时,它告诉我缺少库(Qt5SerialPort ...).在实际的可执行文件上运行ldd
时,我发现该应用程序不是从lib
文件夹中获取所需的库,而是从一些明显的硬编码路径中获取
Till now everything works fine till I call the executable script: the app doesn't run. When I ask to run with sudo
, it tells me that a library (Qt5SerialPort...) is missing. Running ldd
over the actual executable I discover that the app is getting the required libs not from within the lib
folder, but some apparent hard-coded paths.
我尝试使用qt.conf
解决此问题,但未成功.请注意此处,看来qt.conf
实际上不应该以这种方式工作.我决定咨询 Qt文档,使用LD_LIBRARY_PATH
告诉链接器在哪里可以找到库,因为我已经在使用脚本来运行该应用了.因此,最后的摘要脚本代码是
I tried to solve this by using qt.conf
but got no success. As note here, it would seem qt.conf
isn't actually supposed to work this way. Consulting the Qt documentation, I decided to use LD_LIBRARY_PATH
to tell the linker where to find the libs since I was already using a script to run the app anyway. So the final, summarized script code is
#!/bin/sh
LD_LIBRARY_PATH=lib/
export LD_LIBRARY_PATH
sudo ldconfig #sometimes sudo /sbin/ldconfig -v
gksudo "$INSPATH/myApp" #or sudo instead
问题在于它仍然无法正常工作.当我调用echo $LD_LIBRARY_PATH
时,我可以看到该变量已被正确编辑,但是当我调用运行行(使用sudo)时,它一直告诉我找不到lib.
Problem is that it is still not working. When I call echo $LD_LIBRARY_PATH
, I can see the variable was properly edited, but when I call the run line (with sudo), it keeps telling me that lib wasn't found.
我想念什么?
推荐答案
sudo
未通过LD_LIBRARY_PATH
:
$ LD_LIBRARY_PATH=lib/
$ export LD_LIBRARY_PATH
$ env | grep LD_LIBRARY_PATH
LD_LIBRARY_PATH=lib/
$ sudo env | grep LD_LIBRARY_PATH
您可以将其设置为以root身份运行的命令:
You can set it for the command run as root:
$ sudo env LD_LIBRARY_PATH=/lib env | grep LD_LIBRARY_PATH
SUDO_COMMAND=/usr/bin/env LD_LIBRARY_PATH=/lib env
LD_LIBRARY_PATH=/lib
您想要类似的东西
sudo env LD_LIBRARY_PATH=/lib "$INSPATH/myApp"
一如既往,请小心sudo
!
这篇关于LD_LIBRARY_PATH尝试运行Qt应用程序时失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!