Question

cpp-module code:

#include <iostream>
#include <boost/python.hpp>

void Hello()
{
    std::cout << "string: " << PYTHON_API_STRING << "\n";
    std::cout << "int: " << PYTHON_API_VERSION << "\n";
}

BOOST_PYTHON_MODULE(hello)
{
    namespace py = boost::python;
    py::def("Hello", &Hello);
}

compile:

g++ -m32 -Wall -fPIC -I /usr/include -I /usr/include/python2.5/ hello.cpp -L /usr/lib/python2.5/ -Wl,-Bstatic -lboost_python -Wl,-Bdynamic -lgcc -shared -o hello.so

python console (on the same host or other - no difference):

>>> import hello
__main__:1: RuntimeWarning: Python C API version mismatch for module hello: This Python has API version 1013, module hello has version 1012.
>>> hello.Hello()
string: 1013
int: 1013
>>>

Why 1012? Where from?

Was it helpful?

Solution

Python's API version number is changed when there are incompatible changes to some of the internal API calls. Python 2.4 uses a version number of 1012. Python 2.5 and later use version 1013.

You appear to be including Python 2.5 so you should get a version of 1013. The API version is defined in Include/modsupport.h. Is that file corrupt or has it been modified? Does something else override the value?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top