OS X 运行时链接器发现错误的 lib 版本
我的 Python 程序调用了一个 C++ 共享库。 C++ 库是用 HDF5 编译的,我在 OS X 上使用自制程序安装了 HDF5,因此它驻留在 /usr/local/lib
中。现在的问题是我还安装了 PyTables,其中包括旧版本的 libhdf5,安装在 /Library/Frameworks/EPD64.framework/Versions/Current/...
我可以编译和链接我的库很好,otool -L
确实指向 /usr/local/lib/libhdf5.dylib
。但是,当我尝试从 Python 运行它时,出现版本不匹配错误。不知何故,运行时链接器正在加载旧的 hdf5 库。
一种解决方法是将 hdf5 构建为静态库,但我想找到一个更简洁的解决方案 - 如何说服运行时链接器使用较新的库?我已经尝试设置 DYLD_LIBRARY_PATH 但这破坏了其他一切(Python 和 MacVim 无法启动)。
I have a C++ shared library being called from my Python program. The C++ lib is compiled with HDF5 which I installed using homebrew on OS X, so it resides in /usr/local/lib
. Now the problem is that I also have PyTables installed, which includes an older version of libhdf5, installed somewhere in /Library/Frameworks/EPD64.framework/Versions/Current/...
I can compile and link my library just fine, and otool -L
indeed points to /usr/local/lib/libhdf5.dylib
. However, when I try to run it from Python, there is a version mismatch error. Somehow the runtime linker is loading the older hdf5 library instead.
One workaround is to build hdf5 as a static library instead, but I'd like to find a neater solution - how can I persuade the runtime linker to use the newer library? I already tried setting DYLD_LIBRARY_PATH but that just broke everything else (Python and MacVim wouldn't start).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您能提供更多信息吗?我有一些选择(和问题)。
如果我理解正确,您有一个使用 lib_ver_a.dyld 的库和使用 lib_ver_b.dyld 的 pyTables。即相同的库但不同的版本。
您可以:
编译您的库以使用与 pyTables 相同的版本(编译时 DYLD_LIB... )并使用 pyTables 库运行您的程序:DYLD_LIBRARY_PATH=/ Correct/path/lib python myprog.py
升级您的 xcode (您拥有哪个版本) ?还有哪个 osx 版本?)。这会升级你的库和 pyTables(注意,最新的不一定是最稳定的)
你还应该检查你正在调用哪个 python(自定义的还是苹果的)。
还可以在链接时定义特定的 dyld (您使用 gcc 还是 ld 进行链接?我可能会在这里错过一些选项):
gcc /path/lib1.dyld myLib.c -o myLib.o
这样您的库就是链接到该库的某个版本(注意!我不记得确切的细节,但我可以把它们挖出来)。
我希望这有帮助。
br,
尤哈
Can you provide more info? I have a few alternatives (and questions).
If I understood correctly, you have a library that uses lib_ver_a.dyld and pyTables that uses lib_ver_b.dyld. I.e. the same library but different version.
You could either:
Compile your library to use the same version as pyTables (DYLD_LIB... while you compile) and run your program with pyTables library: DYLD_LIBRARY_PATH=/correct/path/lib python myprog.py
Upgrade your xcode (which version you have? also which osx version?). This upgrades your libraries and pyTables (be careful, newest is not necessary the most stable)
You should also check which python you are calling (a custom one or apple one).
There is also a possibility to define a specific dyld while linking (Do you use gcc or ld for linking? I might miss some options here):
gcc /path/lib1.dyld myLib.c -o myLib.o
This way your library is linked to certain version of the library (caution! I don't remember the exact details, but I can dig them out).
I hope this helps.
br,
Juha