【发布时间】:2017-10-26 21:37:24
【问题描述】:
我已经按照以下步骤完成了关于 Cython 的简单教程:
-
制作一个简单的python文件,testme.py:
print("你好!!")
-
使用 cython 创建一个 c 文件:
cython -a testme.py
-
使用 gcc 编译生成的 testme.c 文件:
gcc -Os -I /usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/include/python2.7 -o testme testme.c -lpthread -lm -lutil -ldl
结果是这样的几行:
Undefined symbols for architecture x86_64:
"_PyCode_New", referenced from:
_inittestme in testme-4ef125.o
"_PyDict_New", referenced from:
_inittestme in testme-4ef125.o
"_PyDict_SetItem", referenced from:
_inittestme in testme-4ef125.o
"_PyErr_Clear", referenced from:
_inittestme in testme-4ef125.o
_main in testme-4ef125.o
"_PyErr_Occurred", referenced from:
_inittestme in testme-4ef125.o
_main in testme-4ef125.o
"_PyErr_Print", referenced from:
_main in testme-4ef125.o
"_PyErr_SetString", referenced from:
_inittestme in testme-4ef125.o
"_PyErr_WarnEx", referenced from:
_inittestme in testme-4ef125.o
"_PyExc_ImportError", referenced from:
_inittestme in testme-4ef125.o
"_PyExc_RuntimeError", referenced from:
_inittestme in testme-4ef125.o
显然,缺少链接库。我有以下
/usr/lib/libpython2.6.dylib -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/Python
但是将它添加到 gcc 命令会给我一个 XXX not found 错误:
gcc -Os -I /usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/include/python2.7 -o hello testme.c -l/usr/lib/libpython2.6.dylib -lpthread -lm -lutil -ldl
ld: library not found for -l/usr/lib/libpython2.6.dylib
路径正确。图书馆在那里。
有什么提示吗?
【问题讨论】: