Tôi đang xem qua tài liệu Cython và xây dựng từng ứng dụng mẫu. Tôi có một chút khó khăn khi sử dụng thư viện C. Sau khi xây dựng thành công tệp .so và cố gắng nhập tệp đó vào tệp python có tên test.py, lỗi sau được ném.Ý nghĩa của hàm ImportError này khi nhập tệp .so do Cython tạo ra là gì?
$ 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
Tệp .so nằm ngay bên cạnh tệp test.py. Vì vậy, có vẻ như nó nên được tìm thấy. Điều này đang chạy phiên bản Cython mới nhất, với Python 3.2 trên OSX 10.6.
Mọi thông tin chi tiết?
Chỉnh sửa - thêm xây dựng lệnh và đầu ra
$ 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
Chỉnh sửa 2 - thêm "otool" cmd yêu cầu trong bình luận
queue.so:
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)
Sửa 3 - thêm "nm" đầu ra
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
cmd đầu ra grep này:
(undefined) external _queue_free (dynamically looked up)
Điều này có vẻ giống như sự cố liên kết. Bạn có thể xây dựng lại và bao gồm cả đầu ra xây dựng và lệnh được sử dụng để xây dựng ở đây không? – stderr
@Mike Steder Cảm ơn bạn đã xem xét điều này, tôi đã thêm lệnh xây dựng và đầu ra – JeremyFromEarth
Được rồi, không có nhiều bản sao may mắn vì vậy hãy thử gỡ lỗi thêm một chút. Hãy thử 'nm queue.so' và xem những gì được liệt kê bên cạnh _queue_free. Cũng sử dụng 'otool -L queue.so' và kiểm tra xem DYLD_LIBRARY_PATH (' echo $ DYLD_LIBRARY_PATH'). – stderr