【发布时间】:2011-10-27 11:28:05
【问题描述】:
我正在浏览 Cython 文档并构建每个示例应用程序。我有点卡在使用 C 库上。在成功构建 .so 文件并尝试将其导入名为 test.py 的 python 文件中后,将引发以下错误。
$ python3.2 test.py
Traceback (most recent call last):
File "test.py", line 12, in <module>
from queue import Queue
ImportError: dlopen(/Users/jeremy/Development/labs/python/cython_lib_wrapper/queue.so, 2): Symbol not found: _queue_free
Referenced from: /Users/jeremy/Development/labs/python/cython_lib_wrapper/queue.so
Expected in: flat namespace
in /Users/jeremy/Development/labs/python/cython_lib_wrapper/queue.so
.so 文件位于 test.py 文件旁边。所以,似乎应该找到它。 这是运行最新版本的 Cython,在 OSX 10.6 上使用 Python 3.2。
有什么见解吗?
编辑 - 添加构建命令和输出
$ python3.2 setup.py build_ext --inplace
running build_ext
cythoning queue.pyx to queue.c
building 'queue' extension
gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -O3 -isysroot /Developer/SDKs/MacOSX10.6.sdk -arch i386 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -I/Library/Frameworks/Python.framework/Versions/3.2/include/python3.2m -c queue.c -o build/temp.macosx-10.6-intel-3.2/queue.o
queue.c: In function ‘__pyx_f_5queue_5Queue_append’:
queue.c:627: warning: cast to pointer from integer of different size
queue.c: In function ‘__pyx_f_5queue_5Queue_extend’:
queue.c:740: warning: cast to pointer from integer of different size
queue.c: In function ‘__pyx_f_5queue_5Queue_peek’:
queue.c:813: warning: cast from pointer to integer of different size
queue.c: In function ‘__pyx_f_5queue_5Queue_pop’:
queue.c:965: warning: cast from pointer to integer of different size
gcc-4.2 -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -isysroot /Developer/SDKs/MacOSX10.6.sdk -g build/temp.macosx-10.6-intel-3.2/queue.o -o
编辑 2 - 添加评论中请求的“otool”cmd
queue.so:
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)
编辑 3 - 添加“nm”输出
U ___stack_chk_fail
U ___stack_chk_guard
U _queue_free
U _queue_is_empty
U _queue_new
U _queue_peek_head
U _queue_pop_head
U _queue_push_tail
U dyld_stub_binder
grep cmd 输出:
(undefined) external _queue_free (dynamically looked up)
【问题讨论】:
-
这似乎是一个链接问题。您能否在此处重新构建并包含构建输出和用于构建的命令?
-
@Mike Steder 感谢您查看此内容,我添加了构建命令和输出
-
好的,复制的运气不太好,所以让我们尝试更多的调试。试试
nm queue.so看看 _queue_free 旁边列出了什么。也可以使用otool -L queue.so并查看 DYLD_LIBRARY_PATH (echo $DYLD_LIBRARY_PATH)。 -
我应该从“nm”命令中寻找什么特别的东西吗?输出很长。我已将“otool”的输出添加到原始问题中。
-
也许这可能是两个 calg 文件不在正确位置的问题?我尝试将它们放在 usr/include/calg & usr/lib/calg/ 中,但这导致构建失败。之后,我将它们移到项目文件夹中,并且构建工作正常。另外( echo $DYLD_LIBRARY_PATH )返回一个空行
标签: python shared-libraries cython