[英]Linker error: C/C++ Extensions for python
As my title kind of says, I'm trying to develop a C extension for Python. 就像我的标题所说的那样,我正在尝试为Python开发C扩展。 I followed this tutorial here and I ran the setup.py script.
我在这里遵循了本教程,并运行了setup.py脚本。 How ever when I run the python interpreter and try to import my newly created module, I get a linker error undefined symbol: py_BuildValue.
但是,当我运行python解释器并尝试导入新创建的模块时,却得到了链接器错误未定义符号:py_BuildValue。 I also tryed to compile it my self and I got the same errors plus an error saying Py_InitModule3 is undefined.
我也尝试自己编译它,我得到了相同的错误以及一个错误消息,指出Py_InitModule3未定义。 I have installed both python3.2-dev and python3-dev.
我已经安装了python3.2-dev和python3-dev。 Here is my test.c code:
这是我的test.c代码:
#include <python3.2/Python.h>
static PyObject* Test(PyObject* self){
return py_BuildValue("s","This is a test and my first trip into the world of python bindings!!");
}
static PyMethodDef test_funcs[] ={{"testExtensions",(PyCFunction)Test, METH_NOARGS,"This is my First Extension!!"},{NULL}};
void initTest(void){
Py_InitModule3("Test", test_funcs, "Extension module example!");
}
And my setup.py code: 还有我的setup.py代码:
from distutils.core import setup, Extension
setup(name='Test', version='1.0', \
ext_modules=[Extension('Test', ['test.c'])])
That's because the function is called Py_BuildValue
rather than py_BuildValue
. 这是因为该函数称为
Py_BuildValue
而不是py_BuildValue
。 C is case sensitive. C区分大小写。 If you check further up in your compile messages, you probably also have a warning there about the function being implicitly declared.
如果您进一步检查编译消息,则可能还会有一条警告,提示您隐式声明了该函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.