python - 链接器错误 : C/C++ Extensions for python

标签 python c++ c python-3.x

正如我的标题所说,我正在尝试为 Python 开发 C 扩展。我在这里按照本教程进行操作并运行了 setup.py 脚本。当我运行 python 解释器并尝试导入我新创建的模块时,我得到一个链接器错误 undefined symbol :py_BuildValue。我也尝试自己编译它,但我得到了同样的错误加上一个错误,说 Py_InitModule3 是未定义的。我已经安装了 python3.2-dev 和 python3-dev。这是我的 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!");
}

还有我的 setup.py 代码:

from distutils.core import setup, Extension
setup(name='Test', version='1.0',  \
    ext_modules=[Extension('Test', ['test.c'])])

最佳答案

那是因为该函数被称为 Py_BuildValue 而不是 py_BuildValue。 C 区分大小写。如果您进一步检查编译消息,您可能还会收到有关函数被隐式声明的警告。

关于python - 链接器错误 : C/C++ Extensions for python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25634975/

相关文章:

python - 为网络图重构 pandas 数据框

sql - Oracle Pro*C -- 段错误(核心已转储)

python - Python 中的 Inteviewstreet 中位数。除了第一个测试用例之外的所有测试都失败

python - 将多个列表合并为单一列表格式

C++:在现实世界中添加和重新定义默认参数

Android App Tracking Points : Video. calcOpticalFlow(...) 方法无法正常工作?

c++ - 了解 C++ 分配的内存量

c - R CMD SHLIB 从需要外部库的源 .c 文件创建 DLL(在 Windows x64 上)

c++ - 纹理绑定(bind)的特殊参数?

python - Matplotlib Specgram 得到与 Matlab 相同的结果