0

As my title kind of says, I'm trying to develop a C extension for Python. I followed this tutorial here and I ran the setup.py script. 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. I also tryed to compile it my self and I got the same errors plus an error saying Py_InitModule3 is undefined. I have installed both python3.2-dev and python3-dev. Here is my test.c code:

#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:

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

1 Answer 1

2

That's because the function is called Py_BuildValue rather than py_BuildValue. C is case sensitive. If you check further up in your compile messages, you probably also have a warning there about the function being implicitly declared.

Sign up to request clarification or add additional context in comments.

4 Comments

Oh hmm. I was following a tutorial. Infact the cody is copied and pasted. But I guess that could be it Thanks.
I followed up on this. I have been known do stupid things like that but it would appear that's not the issue.
@rady: Are you sure it's the same error? When I try to compile your code but correct the Py_BuildValue capitalization, the error moves to build about Py_InitModule3 instead, which is understandable since that's a Python 2 function, while at appears you're trying to compile for Python 3.
it is the second error. How would I adapt this for python3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.