For test example, I have this test C++ class which I exported to Python using boost.(from boost website)
#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 by g++ -g -shared -o hello.so -fPIC hello.cpp -lboost_python -lpython2.7 -I/usr/local/include/python2.7
and tested it ok. The test script pp1.py
is like this :
import hello
a = hello.WorldP()
a.set('ahahahah') # <-- line 3
print a.greet()
print('print1')
b = hello.WorldP()
b.set('bhbhbhbh')
print b.greet()
print('print2')
print('program done')
This code runs ok either in interacitive mode and as a script.
ckim@stph45:~/python/hello] python pp1.py
ahahahah
print1
bhbhbhbh
print2
program done
I'm using DDD for visual debugging. When I give the command ddd -pydb pp1.py
, I can do Python code debugging. When I'm inside the debugger, I can give next
command and see the result. But when the debugger is for example in line 3, when I give step
command, it just passes the line not entering into the c++ code. How can I make this work?
(I tried with just gdb, but it's the same- not entering into c++ code.)