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.
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.
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
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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…