Python Cython、OS X和链接错误
我遵循了关于Cython的简单教程,包括以下步骤:Python Cython、OS X和链接错误,python,gcc,cython,Python,Gcc,Cython,我遵循了关于Cython的简单教程,包括以下步骤: 创建一个简单的python文件testme.py: 打印(“你好!!”) 使用cython从中创建一个c文件: cython-a testme.py 使用gcc编译生成的testme.c文件: gcc-Os-I/usr/local/ceral/python/2.7.12_2/Frameworks/python.framework/Versions/2.7/include/python2.7-o testme testme.c-lpthread-
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未找到错误:
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
这条路是正确的。图书馆在那里
有什么提示吗?您需要链接正确的libpython。例如,
-lpython2.7
FWIW
cython
命令的级别有点低(它只处理单个cython模块到C的编译),因为cythonize
命令的级别稍高,可以处理整个包,还包括一个处理C代码编译的--build
选项。这通常比自己尝试构建正确的gcc
命令更容易。谢谢!使用正确的lib成功了。有一件事,我没有看到cython的构建选项。你指的是别的吗?很高兴它起作用了。实际上,--build
选项是cythonize
的一部分。我会更新我的答案。