可以在 Mac OS X 上使用 DYLD_LIBRARY_PATH 吗?而且,它的动态库搜索算法是什么? [英] Is it OK to use DYLD_LIBRARY_PATH on Mac OS X? And, what's the dynamic library search algorithm with it?

查看:26
本文介绍了可以在 Mac OS X 上使用 DYLD_LIBRARY_PATH 吗?而且,它的动态库搜索算法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读了一些不鼓励使用 DYLD_LIBRARY_PATH 的文章,因为动态库的路径应该使用 -install_name、@rpath 和 @loader_path 来固定.

I read some articles discouraging of the use of DYLD_LIBRARY_PATH, as the the path of dynamic library should be fixed using -install_name, @rpath, and @loader_path.

就制作在 Linux 和 Mac OS X 上运行的程序而言,Mac OS X 的 DYLD_LIBRARY_PATH 与 Linux 的 LD_LIBRARY_PATH 完全一样.而且,我们可以共享(几乎)没有 -install_name 和 @rpath 的相同 make 文件.

In terms of making a program that runs both on Linux and Mac OS X, DYLD_LIBRARY_PATH of Mac OS X does exactly what LD_LIBRARY_PATH of Linux. And, we can share (almost) the same make file that doesn't have the -install_name and @rpath.

  • 在 Mac OS X 上使用 DYLD_LIBRARY_PATH 可以吗?
  • 当二进制文件找不到动态库时,Mac OS X 的动态库搜索算法是什么?当前目录 -> DYLD_LIBRARY_PATH 目录...?

推荐答案

正如您所注意到的,DYLD_LIBRARY_PATH 在其他 *nix 上的行为类似于 LD_LIBRARY_PATH.但是,您应该查看另一个名为 DYLD_FALLBACK_LIBRARY_PATH 的环境变量.

As you've noted, DYLD_LIBRARY_PATH behaves like LD_LIBRARY_PATH on other *nix. However, there is another environment variable you should look at called DYLD_FALLBACK_LIBRARY_PATH.

通常,这些(在 osx 和 linux 上)仅建议用于开发用途,因为当您使用不具有相同符号表的库进行覆盖时,它们会导致符号查找错误.一个很好的例子是当您尝试使用自定义安装覆盖 VecLib(例如 blas lapack)的默认安装时.如果设置了 DYLD_LIBRARY_PATH,这将导致链接到系统 VecLib 的应用程序中的符号未找到错误,否则会导致相反(自定义应用程序中的符号查找错误).这是因为系统 blas/lapack 不是 ATLAS 库的完整实现.

In general, these are (both on osx and linux) suggested only for development use as they can cause symbol lookup errors when you override with a library that does not have the same symbol table. A good example of this is when you attempt to override the default install of VecLib (e.g. blas lapack) with a custom install. This will cause symbol not found errors in applications linked to the system VecLib if DYLD_LIBRARY_PATH is set and the reverse (symbol lookup errors in custom applications) if it is not. This is due to the system blas/lapack not being a full implementation of the ATLAS libs.

DYLD_FALLBACK_LIBRARY_PATH 不会产生这些问题.

当将库安装到非标准位置时,DYLD_FALLBACK_LIBRARY_PATH 更加理智.这将在默认路径中提供的库中查找符号,如果在那里找不到符号,则回退到指定的路径.

When installing libraries to a non-standard location, DYLD_FALLBACK_LIBRARY_PATH is much more sane. This will look for symbols in libraries provided in the default paths and if the symbol is not found there, fall back to the specified path.

好处是此过程不会在针对默认库编译的应用程序中导致符号查找错误.

The benefit is that this process will not cause symbol lookup errors in applications compiled against the default libraries.

通常,当库安装到非标准位置时,应指定绝对路径,以消除动态查找的歧义.

In general, when libraries are installed to non-standard locations absolute paths should be specified which negates the ambiguity of the dynamic lookup.

这篇关于可以在 Mac OS X 上使用 DYLD_LIBRARY_PATH 吗?而且,它的动态库搜索算法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆