使用Python ctypes链接XCode dylib

时间:2017-04-05 22:17:14

标签: xcode compilation ctypes pyglet vispy

我正在安装Pyglet作为VisPy的依赖项,但在安装后看到以下错误

File "/Library/Python/2.7/site-packages/pyglet/lib.py", line 160, in load_library

raise ImportError('Library "%s" not found.' % names[0])
ImportError: Library "c" not found.

通过源代码挖掘,我意识到Pyglet正在尝试使用ctypes框架加载标准C库。

进一步挖掘揭示了实际的(未吞下的)错误:

File   "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
OSError: dlopen(/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/lib/libc.dylib, 6): no suitable image found.  Did find:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/lib/libc.dylib: mach-o, but wrong filetype

我认为这个问题类似于架构不匹配的this question。 Python C绑定框架'ctypes'试图使用错误的体系结构加载.dylib。

因为我已将$ LD_LIBRARY_PATH设置为

/Applications.../MacOSX10.10.sdk/usr/lib/

加载程序支持此目录。但是,如果我尝试从标准位置/usr/lib加载“libc.dylib”,一切都会完美无缺。

明显的潜在问题是'libc'的XCode版本适用于32位架构,但/usr/lib适用于64位架构。

不正确!

以下是两个库的file输出:

XCode版本

libc.dylib: Mach-O universal binary with 2 architectures
libc.dylib (for architecture x86_64):   Mach-O 64-bit dynamically linked shared library stub x86_64
libc.dylib (for architecture i386): Mach-O dynamically linked shared library stub i386

/usr/lib

中的标准
/usr/lib/libc.dylib: Mach-O universal binary with 2 architectures
/usr/lib/libc.dylib (for architecture x86_64):  Mach-O 64-bit  dynamically linked shared library x86_64
/usr/lib/libc.dylib (for architecture i386):    Mach-O dynamically linked shared library i386

唯一的区别是XCode版本是“存根”。尽管有一些谷歌搜索,但差异并不完全清楚,虽然看起来“存根”dylib和“非存根”之间的差异是造成问题的原因。

有关我的设置的更多信息:

/usr/bin/python : Python 2.7.10 and appears to be running as a 64-bit app
uname -a: Darwin x-10-104-106-204.uofm-secure.wireless.umn.edu 14.5.0 Darwin Kernel Version 14.5.0: Wed Jul 29 02:26:53 PDT 2015; root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64

我的问题是如何正确链接XCode 安装的dylib?

提前感谢所有想法和建议。

0 个答案:

没有答案