本文介绍了如何使osx上的python加载dylib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图从当前."中加载共享库. dir在osx上进行单元测试.

Trying to load a shared lib out of the current '.' dir in a unit test on osx.

在Linux和Netbsd上有效的是一个符号链接_mymodule.so --> ../.libs/libmymodule.so

What works on Linux and Netbsd there is a symlink _mymodule.so --> ../.libs/libmymodule.so

但是在osx上,找不到python的import mymodule

but on osx, python's import mymodule won't find

_mymodule.dylib --> ../.libs/libmymodule.dylib

我尝试添加

export DYLD_LIBRARY_PATH=.:$DYLD_LIBRARY_PATH

到脚本env,nogo.任何帮助表示赞赏.

to the script env, nogo. Any help appreciated.

-Ed

更新4/6/10:

解决了下面来自krunk的信息.但是仅将dylib复制或ln -s到.so名称并不能完全解决它.仍然不会加载.但是,告诉libtool将lib与-module标志链接会创建一个将加载的.so lib.该库的Python版本现在可以使用.

Solved with the info from krunk below. But just copying or ln -s'ing the dylib to a .so name didn't solve it completely. Still wouldn't load. But telling libtool to link the lib with the -module flag created a .so lib that would load. Python version of the lib works now.

现在,如果我能使perl lib正常工作的话.我正在构建swig perl,python,ruby和lua库,此修复程序仅使python和lua正常工作.

Now if I could just get the perl lib working. I'm building swig perl, python, ruby, and lua libs and this fix only got python and lua working.

推荐答案

在OS X中也要使用* .so作为您的模块扩展名.我有一个无法加载.dylib的模糊记忆,事实证明这是python本身的问题. . .但是我现在找不到邮件列表帖子.

Just use *.so as your module extensions in OS X too. I have a vague memory of not being able to load .dylib's and it turning out to be an issue with python itself. . . but I can't find the mailing list post now.

但是,请放心,您甚至在OS X上使用* .so来遵循标准实践.整个框架中唯一的* .dylib是libsvn_swig.

However, rest assured you're following standard practice by using *.so's even on OS X. The only *.dylib's in the entire framework are the libsvn_swig ones.

find /System/Library/Frameworks/Python.framework/Versions/2.6/ -name "*.so"

/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/X11/xcb/xcb.0.0.0.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/X11/xcb/xcb.0.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/X11/xcb/xcb.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/CoreGraphics/_CoreGraphics.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/OpenSSL/SSL.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/OpenSSL/crypto.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/OpenSSL/rand.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/PyObjC/AppKit/_appmain.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/PyObjC/AppKit/_carbon.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/PyObjC/AppKit/_inlines.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/PyObjC/AppKit/_nsbezierpath.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/PyObjC/AppKit/_nsbitmap.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/PyObjC/AppKit/_nsfont.so
 /System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/PyObjC/AppKit/_nsquickdrawview.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/PyObjC/AppKit/_nsview.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/PyObjC/AppKit/_nswindow.so
/System/Library/Frameworks/Python.framework/Versions/2.6//Extras/lib/python/PyObjC/CFNetwork/_manual.so

这篇关于如何使osx上的python加载dylib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 12:06