cpp模块代码:
#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);
}
编译:
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 控制台(在同一主机或其他主机上 - 没有区别):
>>> 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
>>>
为什么是 1012?从哪里来?