简体   繁体   English

LD_LIBRARY_PATH优先级和编译问题

[英]LD_LIBRARY_PATH precendence and trouble with compiling

I am trying to install some software on a Linux machine (python's rpy2 package, rpy2.robjects in particular, if it matters). 我试图在Linux机器上安装一些软件(python的rpy2包,特别是rpy2.robjects,如果重要的话)。 I need the software to look for its shared libraries in my local space, not in the global spaces like /usr/lib64 whatever. 我需要软件在我的本地空间中查找它的共享库,而不是像/ usr / lib64这样的全局空间。 I do not have admin privileges on this machine. 我没有这台机器的管理员权限。 My problem is that even though I set LD_LIBRARY_PATH to point to my local space, the software still goes to the /usr/lib64/whatever, where it finds libraries that are out of date. 我的问题是,即使我将LD_LIBRARY_PATH设置为指向我的本地空间,软件仍会转到/ usr / lib64 / whatever,它会找到过时的库。 These libraries are missing some objects it needs, so it fails. 这些库缺少它需要的一些对象,因此失败了。 What could be taking precedence over LD_LIBRARY_PATH, and is there a way to change/get rid of it? 什么可以优先于LD_LIBRARY_PATH,有没有办法改变/摆脱它? Thanks. 谢谢。

BTW, someone on this site had a similar question a year or more ago, but his answer involved the env variable RPATH, and changing it with the chrpath utility. 顺便说一下,这个网站上的某个人在一年或更久以前有类似的问题,但他的答案涉及env变量RPATH,并使用chrpath实用程序更改它。 It is not clear to me at all that rpy2 is using RPATH, and chrpath seems unavailable on my system. 我根本不清楚rpy2是否使用RPATH,并且chrpath似乎在我的系统上不可用。

Addendum: I tried running with LD_DEBUG=libs. 附录:我尝试使用LD_DEBUG = libs运行。 Got alot of output that looks like the system is looking for the libs in my LD_LIBRARY_PATH and finding them. 有很多输出,看起来系统正在我的LD_LIBRARY_PATH中寻找lib并找到它们。 Here is where the trouble seems to start: 这是麻烦似乎开始的地方:

/usr/local/lib64/R/library/methods/libs/methods.so: error: symbol lookup error:
undefined symbol: Rf_allocS4Object (fatal)
Error in dyn.load(file, DLLpath = DLLpath, ...) : 
unable to load shared object '/usr/local/lib64/R/library/methods/libs/methods.so':
/usr/local/lib64/R/library/methods/libs/methods.so: undefined symbol: Rf_allocS4Object

So my guess is that the trouble is that whatever is in DLLpath is overriding LD_LIBRARY_PATH. 所以我的猜测是,问题是DLLpath中的任何内容都会覆盖LD_LIBRARY_PATH。 I have tried to change this by prepending my directories to os.environ['PATH'], but no do. 我试图通过将我的目录添加到os.environ ['PATH']来改变这种情况,但是没有。 There is apparently no "DLLPATH", as I thought there would be. 显然没有“DLLPATH”,因为我认为会有。

OK, that's progress, I guess. 好吧,我猜这是进步。 Anybody have anything else? 有人还有别的吗? Thanks. 谢谢。

Have a look at a file named $R_HOME/etc/ldpaths (where in your case $R_HOME seems to be /usr/local/lib64/R). 看一下名为$ R_HOME / etc / ldpaths的文件(在你的情况下,$ R_HOME似乎是/ usr / local / lib64 / R)。 It is the commands in this file that set LD_LIBRARY_PATH at R's start-up. 这个文件中的命令在R的启动时设置LD_LIBRARY_PATH

Mine looks like this: 我看起来像这样:

flodel@netbook-samsung-N150:~$ cat /usr/lib/R/etc/ldpaths 
: ${JAVA_HOME=/usr/lib/jvm/java-6-openjdk/jre}
: ${R_JAVA_LD_LIBRARY_PATH=${JAVA_HOME}/lib/i386/client:${JAVA_HOME}/lib/i386:/usr/lib/jni}
if test -n ""; then
: ${R_LD_LIBRARY_PATH=${R_HOME}/lib:}
else
: ${R_LD_LIBRARY_PATH=${R_HOME}/lib}
fi
if test -n "${R_JAVA_LD_LIBRARY_PATH}"; then
  R_LD_LIBRARY_PATH="${R_LD_LIBRARY_PATH}:${R_JAVA_LD_LIBRARY_PATH}"
fi
if test -z "${LD_LIBRARY_PATH}"; then
  LD_LIBRARY_PATH="${R_LD_LIBRARY_PATH}"
else
  LD_LIBRARY_PATH="${R_LD_LIBRARY_PATH}:${LD_LIBRARY_PATH}"
fi
export LD_LIBRARY_PATH

If you do not have write access to the file, you can still do this before starting R: 如果您没有该文件的写入权限,您仍然可以在启动R之前执行此操作:

export R_LD_LIBRARY_PATH=/your/custom/path

I tested on my machine that it works by running the following after R is started: 我在我的机器上测试了它在R启动后通过运行以下命令来工作:

Sys.getenv("LD_LIBRARY_PATH")
#[1] "/your/custom/path:/usr/lib/jvm/java-6-openjdk/jre/lib/i386/client:/usr/lib/jvm/java-6-openjdk/jre/lib/i386:/usr/lib/jni"

If anyone is still reading this, I engaged in some "personnel engineering" to solve the problem, ie got the system admins to re-install R so that it had everything I needed. 如果有人还在读这个,我参与了一些“人事工程”来解决问题,即让系统管理员重新安装R,以便它拥有我需要的一切。 Was certainly nice of them. 他们当然很好。 Thanks very much to everyone who gave suggestions. 非常感谢所有提出建议的人。 Would like to keep going on some of them, but I've got to get busy on this project. 我想继续其中一些,但我必须忙于这个项目。 Much obliged! 非常感谢!

RPATH is only useful when compiling (well, linking); RPATH仅在编译时有用(好吧,链接); it affects the library search path that gets baked into the binary. 它会影响到二进制文件中的库搜索路径。

Try running with LD_DEBUG=libs , which will show libraries are being loaded from which paths. 尝试使用LD_DEBUG=libs运行,这将显示从哪些路径加载库。 Is it trying to load from your LD_LIBRARY_PATH but failing, or not searching there in the first place (perhaps rpy2 has its own library path mechanism?), or something else? 它是否尝试从LD_LIBRARY_PATH加载但是失败,或者首先不在那里搜索(也许rpy2有自己的库路径机制?),还是其他什么?

尝试添加LD_LIBRARY_PATH左侧的目录,因为优先级从左到右。

export LD_LIBRARY_PATH=~/your/custom/path:$LD_LIBRARY_PATH

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM