我试图用^ {< CD1>}将一个C++类暴露给Python,所以我要通过this tutorial。我用以下源代码创建了一个visual studio .dll项目:#include
using namespace boost::python;
struct World
{
void set(std::string msg) { this->msg = msg; }
std::string greet() { return msg; }
std::string msg;
};
BOOST_PYTHON_MODULE(hello)
{
class_("World")
.def("greet", &World::greet)
.def("set", &World::set)
;
}
我把它构建成一个64位的dll。本教程的下一步是:Here, we wrote a C++ class wrapper that exposes the member functions greet and set. Now, after building our module as a shared library, we may use our class World in Python. Here's a sample Python session:
^{pr2}$
但是,在同一目录中启动python并键入import hello之后,我得到>>> import hello
Traceback (most recent call last):