我试图让python-sybase模块在OSX 10.6上工作,但我遇到了一些麻烦.
当我做
import Sybase
我明白了
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "Sybase.py", line 15, in <module>
from sybasect import *
ImportError: dlopen(/Library/Python/2.6/site-packages/python_sybase-0.40pre2-py2.6-macosx-10.6-universal.egg/sybasect.so, 2): Symbol not found: _blk_alloc
Referenced from: /Library/Python/2.6/site-packages/python_sybase-0.40pre2-py2.6-macosx-10.6-universal.egg/sybasect.so
Expected in: flat namespace
in /Library/Python/2.6/site-packages/python_sybase-0.40pre2-py2.6-macosx-10.6-universal.egg/sybasect.so
我看了一下sybasect.so,果然,_blk_alloc是未定义的.该函数位于已安装的Sybase的sybblk.dylib中,其包含的目录位于LD_LIBRARY_PATH中.
当我使用python setup.py build编译python-sybase时,gcc命令似乎可以正确找到所有正确的库,但由于某些原因,在将sybasect.so安装到Python模块目录后,这些库似乎没有链接.
gcc命令是
gcc-4.2 -Wl,-F. -bundle -undefined dynamic_lookup -arch i386 -arch ppc -arch x86_64 build/temp.macosx-10.6-universal-2.6/blk.o build/temp.macosx-10.6-universal-2.6/databuf.o build/temp.macosx-10.6-universal-2.6/cmd.o build/temp.macosx-10.6-universal-2.6/conn.o build/temp.macosx-10.6-universal-2.6/ctx.o build/temp.macosx-10.6-universal-2.6/datafmt.o build/temp.macosx-10.6-universal-2.6/iodesc.o build/temp.macosx-10.6-universal-2.6/locale.o build/temp.macosx-10.6-universal-2.6/msgs.o build/temp.macosx-10.6-universal-2.6/numeric.o build/temp.macosx-10.6-universal-2.6/money.o build/temp.macosx-10.6-universal-2.6/datetime.o build/temp.macosx-10.6-universal-2.6/date.o build/temp.macosx-10.6-universal-2.6/sybasect.o -L/Applications/Sybase/System/OCS-15_0/lib -lsybblk -lsybct -lsybcs -lsybtcl -lsybcomn -lsybintl -lsybunic -o build/lib.macosx-10.6-universal-2.6/sybasect.so
-L / Applications / Sybase / System / OCS-15_0 / lib位置正确,该文件夹包含所有正确的.dylib.
当我运行otool时,输出是:
$otool -L build/lib.macosx-10.6-universal-2.6/sybasect.so
build/lib.macosx-10.6-universal-2.6/sybasect.so:
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.11)
我期待在那里看到Sybase库.
我对Mac上的链接有点新意.如何确保sybasect.so引用Sybase库?
解决方法:
固定它.
问题是我链接的各种Sybase库只有32位,但我在64位模式下运行Python.修复程序只是在32位模式下运行python.
我使用命令defaults write com.apple.versioner.python Prefer-32-Bit -bool yes,因为我对64位模式没有任何特殊需要.