6

I'm aware of the general basics of using ldconfig and LD_LIBRARY_PATH, but I'm hoping for a little guru help with my situation.

I have a portable software package that resides in its own directory and has its own versions of many libraries.

There are MANY binaries and scripts that run from this directory.

Some of the binaries (apache, php, postgres) may also have separate versions installed on the system.

Since there might be two versions of php, it doesn't suffice to create /etc/ld.so.conf.d/myapp.conf if the system can't determine which version of "myapp" to use the ldconfig file for.

I'm looking for best practices on configuring such a system. The person who initially set up the software pack exported LD_LIBRARY_PATH so that ALL applications on the system used it.

I'm trying to isolate just the applications in the package directory.

Some parameters to work with:

/mypack - contains everything for the software package

/mypack/local/lib - contains required libraries that may not be compatible with the system

library example:

/mypack/local/lib/libz.so.1 => /mypack/local/lib/libz.so.1.2.3
/lib/libz.so.1 => /lib/libz.so.1.2.3

even though the versions are the same, the one in /mypack may not be compatible with the distro and will break the system if it's used

binary example: php exists in both /mypack and in the default directory php from /mypack should use libs from /mypack/local/lib and the distro version should use /lib

Some questions about linux library paths: - Is it possible to specify /etc/ld.so.conf.d/php.conf such that it only affects the version of php in /mypack? - Can the library path be specified based on the location of an executable? That is, at run time, if the path of an executable is under /mypack, can it automatically use libraries from there? - How about on a per user basis? Some/most of the system runs on different user accounts. If I were able to set a different library path per user, that would solve it.

4

2 回答 2

5

万一其他人发现这很有用,我最终在构建之前这样做了:

export LD_RUN_PATH='$ORIGIN/../lib'

这包括二进制文件本身中的库路径,相对于二进制文件的位置。如果您打算在 bash 脚本或构建文件中使用它,请确保使用 $ORIGIN 查找您的特定用法,因为在某些情况下您需要执行诸如 \$$ORIGIN、\$$ORIGIN 或 $$ 之类的操作ORIGIN 以便构建中涉及的不同实用程序正确转义美元符号。找到这个有用的部分让我不必更新大约 50 个单独的脚本,这些脚本作为批处理运行来构建我们的软件包。

于 2013-07-29T08:01:18.240 回答
0

通常的问题是 LD_LIBRARY_PATH 位于 ldconfig 提供的信息之前。如果您只想拥有一组备份库以在尚未拥有它们的系统上安装,请从 ldconfig 中提取当前的一组库并将它们添加到 LD_LIBRARY_PATH

mytmp=/tmp/${USER}_junk$$
( for i in `/sbin/ldconfig -p | grep '=>' | awk '{ print $NF }'` ; do   dirname $i ; done ) | sort -r | uniq > ${mytmp}
myld=""
for j in `cat ${mytmp}` ; do myld=${j}:${myld} ; done
rm -f ${mytmp}
LD_LIBRARY_PATH=${myld}${LD_LIBRARY_PATH}:${SEP}/lib:${SEP}/lib/syslibs
export LD_LIBRARY_PATH
于 2016-02-01T01:29:30.347 回答