In the test case, I have this C ++ test class that I exported to Python using boost. (from boost site)
#include <boost/python.hpp>
using namespace boost::python;
struct WorldC
{
void set(std::string msg) { this->msg = msg; }
std::string greet() { return msg; }
std::string msg;
};
BOOST_PYTHON_MODULE(hello)
{
class_<WorldC>("WorldP")
.def("greet", &WorldC::greet)
.def("set", &WorldC::set)
;
}
I compiled this code g++ -g -shared -o hello.so -fPIC hello.cpp -lboost_python -lpython2.7 -I/usr/local/include/python2.7and tested it in order. The test script pp1.pylooks like this:
import hello
a = hello.WorldP()
a.set('ahahahah')
print a.greet()
print('print1')
b = hello.WorldP()
b.set('bhbhbhbh')
print b.greet()
print('print2')
print('program done')
This code works fine either interactively or as a script.
ckim@stph45:~/python/hello] python pp1.py
ahahahah
print1
bhbhbhbh
print2
program done
DDD . ddd -pydb pp1.py, Python. , next . , , 3, step, , ++. ?
( gdb, , ++.)