3

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?

user694989
  • 75
  • 6

1 Answers1

1

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?

casevh
  • 11,093
  • 1
  • 24
  • 35
  • Reason is boost configured for python 2.4 a long time ago. – user694989 Jul 31 '13 at 12:42
  • Аll right. Reason is boost configured for python 2.4 a long time ago. Then python 2.4 was installed. But is not now. remove libboost_python and rebuild boost have eliminated the mismatch. – user694989 Jul 31 '13 at 12:50