我想在c中編寫一個python擴展。我在Mac上工作,我參加了一個代碼here:Python擴展:找不到架構x86_64錯誤的符號
#include <Python.h>
static PyObject* say_hello(PyObject* self, PyObject* args)
{
const char* name;
if (!PyArg_ParseTuple(args, "s", &name))
return NULL;
printf("Hello %s!\n", name);
Py_RETURN_NONE;
}
static PyMethodDef HelloMethods[] =
{
{"say_hello", say_hello, METH_VARARGS, "Greet somebody."},
{NULL, NULL, 0, NULL}
};
PyMODINIT_FUNC
inithello(void)
{
(void) Py_InitModule("hello", HelloMethods);
}
我編譯:
gcc -c -o py_module.o py_module.c -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/
gcc -o py_module py_module.o -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/ -lm
但我得到這個錯誤:
Undefined symbols for architecture x86_64:
"_PyArg_ParseTuple", referenced from:
_say_hello in py_module.o
"_Py_InitModule4_64", referenced from:
_inithello in py_module.o
"__Py_NoneStruct", referenced from:
_say_hello in py_module.o
"_main", referenced from:
start in crt1.10.6.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [py_module] Error 1
如何來Python不支持X86_64
架構?
其中靜態蟒LIB可以找到? – 0x90 2013-03-26 07:55:24
取決於您的操作系統和Python安裝。在我的盒子裏,它在'/ usr/lib'中(實際上,對於不同版本的Python,有一大堆庫)。 – NPE 2013-03-26 07:57:49
我沒有找到一個python靜態庫'find/-iname * libpython * 2>&1 | grep -v「^ find」'only'.dylib'和'.a'文件 – 0x90 2013-03-26 08:21:43