我正在尝试在this gist的OSX10.9上构建这个示例:
cd /tmp
git clone https://gist.github.com/ecfd80885b9ddf6734192c056cf48bf4.git fopentest
cd fopentest
bash buildrun.sh构建成功了-而且,我可以在终端输出中看到以下内容:
...
+ DYLD_BIND_AT_LAUNCH=YES
+ ./fopentest.exe ./mytestfile.txt
This is a wrapper function for fopen.
=== this is mytestfile.txt ===
Second line here...
Third line here...这意味着调用DYLD_BIND_AT_LAUNCH=YES ./fopentest.exe ./mytestfile.txt成功地找到了包装库和函数。
现在,作为测试,我想通过dtruss,OSX “strace” equivalent来运行这个可执行文件--我也按照链接中推荐的那样运行了sudo chmod u+s /usr/sbin/dtrace。所以我在/tmp文件夹中尝试了一下:
$ DYLD_BIND_AT_LAUNCH=YES dtruss ./fopentest.exe ./mytestfile.txt 2>&1 | grep wrap
This is a wrapper function for fopen.
stat64("libwrapper.dylib\0", 0x7FFF5A7DF248, 0x7FFF5A7E00E0) = 0 0
open("libwrapper.dylib\0", 0x0, 0x0) = 3 0
write_nocancel(0x1, "This is a wrapper function for fopen.\n=== this is mytestfile.txt ===\nSecond line here...\nThird line here...\n\0", 0x6C) = 108 0所以,很明显,这里的dtruss是有效的。但是,我在不同的目录中有完全相同的文件,所以我尝试运行相同的命令,dtruss失败:
$ DYLD_BIND_AT_LAUNCH=YES dtruss ./fopentest.exe ./mytestfile.txt 2>&1 | grep wrap
dyld: Library not loaded: libwrapper.dylib
stat64("libwrapper.dylib\0", 0x7FFF4FD85228, 0x7FFF4FD860C0) = 0 0
open("libwrapper.dylib\0", 0x0, 0x0) = -1 Err#2
stat64("/Users/MYNAME/lib/libwrapper.dylib\0", 0x7FFF4FD85A08, 0x7FFF4FD860C0) = -1 Err#2
stat64("/usr/local/lib/libwrapper.dylib\0", 0x7FFF4FD85A08, 0x7FFF4FD860C0) = -1 Err#2
stat64("/usr/lib/libwrapper.dylib\0", 0x7FFF4FD85A18, 0x7FFF4FD860C0) = -1 Err#2这可能是什么原因呢?
发布于 2017-10-08 22:03:18
嗯,我想我知道原因是什么了:dtruss找不到库的目录实际上是通过sshfs挂载的;mount为该路径显示了以下内容:
MYOTHERNAME@myRemotePC:/media/Test1 on /media/Test1 (osxfusefs, nodev, nosuid, synchronous, mounted by MYNAME)因此,如果我尝试在/media/Test1/fopentest/中调用DYLD_BIND_AT_LAUNCH=YES dtruss ./fopentest.exe ./mytestfile.txt,则会得到"dyld: Library not loaded: libwrapper.dylib“。
但是,如果我将文件夹移动到“正确”文件系统中的其他位置,比如在$HOME:mv /media/Test1/fopentest ~/中,我甚至不需要重新构建,我只需在~/fopentest/中调用DYLD_BIND_AT_LAUNCH=YES dtruss ./fopentest.exe ./mytestfile.txt,调用就会成功……
不确定为什么会发生这种情况--所以如果能提供更丰富的答案,我们将非常感谢……
https://stackoverflow.com/questions/46631701
复制相似问题