4

对于测试示例,我有这个测试 C++ 类,我使用 boost 导出到 Python。(来自 boost 网站)

#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)
    ;
}

我编译了这段代码g++ -g -shared -o hello.so -fPIC hello.cpp -lboost_python -lpython2.7 -I/usr/local/include/python2.7并测试了它。测试脚本pp1.py是这样的:

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')

此代码在交互模式下和作为脚本都可以正常运行。

ckim@stph45:~/python/hello] python pp1.py
ahahahah
print1
bhbhbhbh
print2
program done

我正在使用 DDD 进行可视化调试。当我发出命令ddd -pydb pp1.py时,我可以进行 Python 代码调试。当我在调试器中时,我可以发出next命令并查看结果。但是当调试器例如在第 3 行时,当我发出step命令时,它只是传递了没有进入 c++ 代码的行。我怎样才能使这项工作?(我只尝试了 gdb,但它是一样的 - 没有进入 c++ 代码。)

4

0 回答 0