Macos Cython在Mac OS X 10.8上编译/链接失败

Macos Cython在Mac OS X 10.8上编译/链接失败,macos,osx-mountain-lion,cython,Macos,Osx Mountain Lion,Cython,我是python的新手,试着用一个建立在 cython文件名为c1.pyx 然后运行cythonc1.pyx,一切正常。 然后运行gcc-c-fPIC-I/usr/include/python2.7/c1.c,也很好。 但是运行gcc-shared c1.o-oc1.so,它没有通过 有人能解释一下吗 以下是错误消息: Undefined symbols for architecture x86_64: "_PyCFunction_NewEx", referenced from:

我是python的新手,试着用一个建立在 cython文件名为c1.pyx

然后运行cythonc1.pyx,一切正常。 然后运行
gcc-c-fPIC-I/usr/include/python2.7/c1.c
,也很好。 但是运行
gcc-shared c1.o-oc1.so
,它没有通过

有人能解释一下吗

以下是错误消息:

Undefined symbols for architecture x86_64:
  "_PyCFunction_NewEx", referenced from:
      _initc1 in cc5xSgOI.o
  "_PyCode_New", referenced from:
      ___Pyx_AddTraceback in cc5xSgOI.o
      _initc1 in cc5xSgOI.o
  "_PyDict_GetItem", referenced from:
      ___pyx_pw_2c1_1great_circle in cc5xSgOI.o
  "_PyDict_New", referenced from:
      _initc1 in cc5xSgOI.o
  "_PyDict_Next", referenced from:
      ___pyx_pw_2c1_1great_circle in cc5xSgOI.o
  "_PyDict_Size", referenced from:
      ___pyx_pw_2c1_1great_circle in cc5xSgOI.o
  "_PyErr_Clear", referenced from:
      ___Pyx_GetName in cc5xSgOI.o
  "_PyErr_Format", referenced from:
      ___Pyx_RaiseArgtupleInvalid.constprop.5 in cc5xSgOI.o
      ___pyx_pw_2c1_1great_circle in cc5xSgOI.o
  "_PyErr_Occurred", referenced from:
      ___pyx_pw_2c1_1great_circle in cc5xSgOI.o
      _initc1 in cc5xSgOI.o
  "_PyErr_SetObject", referenced from:
      ___Pyx_GetName in cc5xSgOI.o
  "_PyErr_SetString", referenced from:
      _initc1 in cc5xSgOI.o
  "_PyErr_WarnEx", referenced from:
      _initc1 in cc5xSgOI.o
  "_PyExc_ImportError", referenced from:
      _initc1 in cc5xSgOI.o
  "_PyExc_NameError", referenced from:
      ___Pyx_GetName in cc5xSgOI.o
  "_PyExc_TypeError", referenced from:
      ___Pyx_RaiseArgtupleInvalid.constprop.5 in cc5xSgOI.o
      ___pyx_pw_2c1_1great_circle in cc5xSgOI.o
  "_PyFloat_AsDouble", referenced from:
      ___pyx_pw_2c1_1great_circle in cc5xSgOI.o
  "_PyFloat_FromDouble", referenced from:
      ___pyx_pw_2c1_1great_circle in cc5xSgOI.o
  "_PyFloat_Type", referenced from:
      ___pyx_pw_2c1_1great_circle in cc5xSgOI.o
  "_PyFrame_New", referenced from:
      ___Pyx_AddTraceback in cc5xSgOI.o
  "_PyImport_AddModule", referenced from:
      _initc1 in cc5xSgOI.o
  "_PyInt_FromLong", referenced from:
      _initc1 in cc5xSgOI.o
  "_PyList_New", referenced from:
      _initc1 in cc5xSgOI.o
  "_PyMem_Malloc", referenced from:
      ___Pyx_AddTraceback in cc5xSgOI.o
  "_PyMem_Realloc", referenced from:
      ___Pyx_AddTraceback in cc5xSgOI.o
  "_PyModule_GetDict", referenced from:
      ___Pyx_AddTraceback in cc5xSgOI.o
      _initc1 in cc5xSgOI.o
  "_PyNumber_Add", referenced from:
      ___pyx_pw_2c1_1great_circle in cc5xSgOI.o
  "_PyNumber_Multiply", referenced from:
      ___pyx_pw_2c1_1great_circle in cc5xSgOI.o
  "_PyOS_snprintf", referenced from:
      _initc1 in cc5xSgOI.o
  "_PyObject_Call", referenced from:
      ___pyx_pw_2c1_1great_circle in cc5xSgOI.o
  "_PyObject_CallFunctionObjArgs", referenced from:
      _initc1 in cc5xSgOI.o
  "_PyObject_GetAttr", referenced from:
      ___Pyx_GetName in cc5xSgOI.o
      ___pyx_pw_2c1_1great_circle in cc5xSgOI.o
  "_PyObject_GetAttrString", referenced from:
      _initc1 in cc5xSgOI.o
  "_PyObject_SetAttr", referenced from:
      _initc1 in cc5xSgOI.o
  "_PyObject_SetAttrString", referenced from:
      _initc1 in cc5xSgOI.o
  "_PyString_AsString", referenced from:
      ___pyx_pw_2c1_1great_circle in cc5xSgOI.o
  "_PyString_FromFormat", referenced from:
      ___Pyx_AddTraceback in cc5xSgOI.o
  "_PyString_FromString", referenced from:
      ___Pyx_AddTraceback in cc5xSgOI.o
  "_PyString_FromStringAndSize", referenced from:
      _initc1 in cc5xSgOI.o
  "_PyString_InternFromString", referenced from:
      _initc1 in cc5xSgOI.o
  "_PyString_Type", referenced from:
      ___pyx_pw_2c1_1great_circle in cc5xSgOI.o
  "_PyTraceBack_Here", referenced from:
      ___Pyx_AddTraceback in cc5xSgOI.o
  "_PyTuple_New", referenced from:
      ___pyx_pw_2c1_1great_circle in cc5xSgOI.o
      _initc1 in cc5xSgOI.o
  "_PyUnicodeUCS2_DecodeUTF8", referenced from:
      _initc1 in cc5xSgOI.o
  "_Py_GetVersion", referenced from:
      _initc1 in cc5xSgOI.o
  "_Py_InitModule4_64", referenced from:
      _initc1 in cc5xSgOI.o
  "__PyString_Eq", referenced from:
      ___pyx_pw_2c1_1great_circle in cc5xSgOI.o
  "__PyThreadState_Current", referenced from:
      ___Pyx_AddTraceback in cc5xSgOI.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

您必须在链接器命令行中包含
-lpython2.7
(或您正在使用的任何Python版本)

不过,使用Cython最简单的方法是使用distutils设置脚本,因为它将为您执行所有的基本编译器命令


另请参见:,。

谢谢,它已正确编译,但仍存在运行时错误。不管怎样,我按照你的建议继续使用distutils,效果很好。