为什么不是DYLD_LIBRARY_PATH这里正在传播? [英] Why isn't DYLD_LIBRARY_PATH being propagated here?

查看:270
本文介绍了为什么不是DYLD_LIBRARY_PATH这里正在传播?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我试图运行,针对一个版本,我建previously的Boost.Thread库连接的C ++程序。我似乎无法理解的运行时库路径表现在OS X上的方式

I have a simple C++ program that I'm trying to run that is linked against a version of the Boost.Thread library that I built previously. I seem to be having trouble understanding the way that runtime library paths behave on OS X.

由于我Boost库不具有<一个href=\"https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/RunpathDependentLibraries.html\"相对=nofollow> RPATH相对安装名称,我使用了 DYLD_LIBRARY_PATH 环境变量来告诉动态链接程序在哪里可以找到 libboost_thread.dylib 在运行时。

Since my Boost library doesn't have an RPATH-relative install name, I'm using the DYLD_LIBRARY_PATH environment variable to tell the dynamic linker where to find libboost_thread.dylib at runtime.

如果我直接在运行该程序能正常工作,我的(庆典)的外壳:

This works fine if I run the program directly in my (bash) shell:

[~/git/project]$ echo $DYLD_LIBRARY_PATH
/Users/jasonr/git/project/boost/lib
[~/git/project]$ .sconf_temp/conftest_7
[~/git/project]$ # Program runs successfully; this is what I expect.

不过,这个程序运行作为由的autoconf 样的框架,我使用了一系列的测试的一部分。它运行使用一个子shell程序 SH -c 。这里会发生什么,如果我尝试:

However, this program is run as part of a series of tests by an autoconf-like framework that I'm using. It runs the program in a child shell using sh -c. Here's what happens if I try that:

[~/git/project]$ # Make sure the environment variable is exported to child shells.
[~/git/project]$ export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH
[~/git/project]$ # Try to run it in a child shell.
[~/git/project]$ sh -c .sconf_temp/conftest_7
dyld: Library not loaded: libboost_thread.dylib
  Referenced from: /Users/jasonr/git/project/.sconf_temp/conftest_7
  Reason: image not found
Trace/BPT trap: 5

这是因为如果在这种情况下,环境变量不会传播到 dyld的。为什么会发生?我更熟悉的 LD_LIBRARY_PATH 在Linux上,这(我认为)的行为应与上面的例子中工作。有没有别的东西,我需要为了使这项工作呢?

It's as if the environment variable isn't propagated to dyld in this case. Why would this occur? I'm more familiar with the behavior of LD_LIBRARY_PATH on Linux, which (I think) should work with the above example. Is there something else I need to do in order to make this work?

推荐答案

presumably,您正在运行埃尔卡皮坦(OS X 10.11)。这是系统完整性保护的副作用。从<一个href=\"https://developer.apple.com/library/$p$prelease/mac/documentation/Security/Conceptual/System_Integrity_Protection_Guide/RuntimeProtections/RuntimeProtections.html\"相对=nofollow>系统完整性保护指南:运行时栅栏文章:

Presumably, you are running El Capitan (OS X 10.11). It's a side effect of System Integrity Protection. From the System Integrity Protection Guide: Runtime Protections article:

当开始一个进程,内核检查以查看是否在主
  可执行文件是受保护的磁盘上或与一个特殊的系统签约
  权利。如果任一为真,则标志被设置以表示它
  被保护,以防止变形。 ...

When a process is started, the kernel checks to see whether the main executable is protected on disk or is signed with an special system entitlement. If either is true, then a flag is set to denote that it is protected against modification. …

...任何动态连接器( dyld的
  环境变量,如 DYLD_LIBRARY_PATH ,将被清除时,
  启动保护程序。

… Any dynamic linker (dyld) environment variables, such as DYLD_LIBRARY_PATH, are purged when launching protected processes.

所有系统提供间preters,包括 / bin / sh的,以这种方式得到保护的。因此,当你调用 SH ,所有DYLD_ *环境变量被清除。

All of the system-provided interpreters, including /bin/sh, are protected in this fashion. Therefore, when you invoke sh, all DYLD_* environment variables are purged.

您可以写一个shell脚本,设置 DYLD_LIBRARY_PATH ,然后执行 .sconf_temp / conftest_7 。您可以使用外壳间preTER来执行 - 事实上,你必须 - 和环境变量将被罚款,因为当一个受保护的可执行文件开始吹扫发生。基本上,这种方法类似于你的问题的工作的例子,但在shell脚本封装。

You could write a shell script which sets DYLD_LIBRARY_PATH and then executes .sconf_temp/conftest_7. You can use the the shell interpreter to execute that — indeed, you must — and the environment variable will be fine, since the purging happens when a protected executable is started. Basically, this approach is analogous to the working example in your question, but encapsulated in a shell script.

这篇关于为什么不是DYLD_LIBRARY_PATH这里正在传播?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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