I've taken a library that is distributed as a binary lib (.a) and header, written some c++ code against it, and want to wrap the results up in a python module.
我使用了一个作为二进制库(.a)和header分发的库,并针对它编写了一些c++代码,并希望将结果封装在一个python模块中。
I've done this here.
我做了这个。
The problem is that when importing this module on Mac OSX (I've tried 10.5 and 10.6), I get the following error:
问题是在Mac OSX上导入这个模块时(我尝试了10.5和10.6),我得到了以下错误:
dlopen(/Library/Python/2.5/site-packages/dirac.so, 2): Symbol not found: _DisposePtr
Referenced from: /Library/Python/2.5/site-packages/dirac.so
Expected in: dynamic lookup
This looks like symbols defined in the Carbon framework aren't being properly resolved, but I'm not sure what to do about that. I am supplying -framework Carbon
to distutil.core.Extension
's extra_link_args
parameter, so I'm not sure what else I should do.
看起来碳框架中定义的符号并没有得到正确的解析,但是我不知道该怎么做。我在向distutil.core提供-framework碳。扩展的extra_link_args参数,因此我不确定还应该做什么。
Any help would be much appreciated.
如有任何帮助,我们将不胜感激。
Update:
更新:
The compile line generated by setup.py looks like this:
安装程序生成的编译行。py是这样的:
gcc -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-common -dynamic -DNDEBUG -g -Os -Wall -Wstrict-prototypes -DMACOSX -I/usr/include/ffi -DENABLE_DTRACE -arch i386 -arch ppc -pipe -Isource -I/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/numpy/core/include -I/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/numpy/numarray -I/usr/lib/python/2.5/site-packages/numpy/numarray/numpy -I/usr/lib/python/2.5/site-packages/numpy/numarray -I/usr/lib/python/2.5/site-packages/numpy/core/include -I/System/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -c source/Dirac_LE.cpp -o build/temp.macosx-10.5-i386-2.5/source/Dirac_LE.o
The linker line looks like this:
链接器线是这样的:
g++ -Wl,-F. -bundle -undefined dynamic_lookup -arch i386 -arch ppc build/temp.macosx-10.5-i386-2.5/diracmodule.o build/temp.macosx-10.5-i386-2.5/source/Dirac_LE.o -Llibs/MacOSX -lDiracLE -o build/lib.macosx-10.5-i386-2.5/dirac.so -framework Carbon
otool
reports:
otool报告:
dirac.so:
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.4.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.5)
Update 2: On MacOS 10.5, modifying the dlopen flags from the default of RTLD_NOW
to RTLD_LAZY
solves the problem. However, this does not work on Mac OS 10.6.
更新2:在MacOS 10.5上,将dlopen标志从RTLD_NOW的默认修改为RTLD_LAZY就解决了这个问题。然而,这在Mac OS 10.6上并不适用。
On 10.6, the following sequence allows the library to run properly, although I'm not sure why:
在10.6,下面的序列允许库正常运行,尽管我不确定为什么:
- python setup.py build -v
- python的设置。py构建- v
- run the linker line (printed to console by setup.py) again, manually.
- 再次手动运行链接器行(通过setup.py打印到控制台)。
- python setup.py install
- python的设置。py安装
I'm still looking for a good answer as to how to get this to work properly. Thanks!
我仍然在寻找一个好的答案,关于如何使它正常工作。谢谢!
1 个解决方案
#1
4
You're going to kick yourself when you see the answer to this! Try changing this:
当你看到这个问题的答案时,你会后悔的!试着改变:
link_args = ['-framework Carbon'] if platform == 'Darwin' else []
to this:
:
link_args = ['-framework', 'Carbon'] if platform == 'Darwin' else []
Once I made this change I was able to do a clean build and import the module straight away :)
一旦我做了这个改变,我就能做一个干净的构建并直接导入模块:)
#1
4
You're going to kick yourself when you see the answer to this! Try changing this:
当你看到这个问题的答案时,你会后悔的!试着改变:
link_args = ['-framework Carbon'] if platform == 'Darwin' else []
to this:
:
link_args = ['-framework', 'Carbon'] if platform == 'Darwin' else []
Once I made this change I was able to do a clean build and import the module straight away :)
一旦我做了这个改变,我就能做一个干净的构建并直接导入模块:)