Python扩展:符号(S)没有发现建筑x86_64的错误 [英] Python extension: symbol(s) not found for architecture x86_64 error
本文介绍了Python扩展:符号(S)没有发现建筑x86_64的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要写在C Python扩展。我在Mac上工作,我花了code从这里:
I want to write a python extension in c. I work on Mac, I took a code from here:
#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
但我得到这个错误:
But I get this error:
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
架构?
推荐答案
两件事情:
- 您需要将您的扩展链接作为共享对象(你试图链接可执行文件,这就是为什么连接器正在寻找
的main()
) - 您需要对Python的静态库(
-lpython
)链接。
- You need to link your extension as a shared object (you're attempting to link an executable, which is why the linker is looking for
main()
); - You need to link against the Python static library (
-lpython
).
这篇关于Python扩展:符号(S)没有发现建筑x86_64的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文