开发者

Painless way to get C++ extensions in Python in Visual Studio 2005

I'm having some very serious compatibility issues with STLPort 5.1.0 and Boot.Python 1.46.1 in Visual Studio 2005, I was wondering if there was any other way to have Python calling C++ code.

Just in case someone can help: The following code compiels and runs without issue: char const* greet() { return "hello, world"; }

BOOST_PYTHON_MODULE(hello_ext)
{
    using namespace boost::python;
    def("greet", greet);
}

The linking errors start when I do something slightly more complex:

#include <iostream>
#include <boost/python.hpp>
using namespace boost::python;

struct World
{
    std::string msg;
    double mypi;

    World(std::string msg): msg(msg) {} // added constructor
    void set(std::string msg) { this->msg = msg; }
    std::string greet() { return msg; }
    double get() const { return mypi; }
    void setter(double mypi) { this->mypi = mypi; }


};

BOOST_PYTHON_MODULE(hello_ext)
{
    class_<World>("World", init<std::string>())
        .def("greet", &World::greet)
        .def("set", &World::set)
        .def_readonly("msg",  &World::msg)
        .def_readwrite("mypi", &World::mypi)
        .add_property("rovalue", &World::get)
        .add_property("value", &World::get, &World::setter)
    ;
}

Unfortunately, I've been so frustrated that I've mangled my code to a point where I can reproduce the linkin开发者_开发技巧g errors because other compile errors are appearing. But the errors were linking errors for undefined symbols beginning with 'stlp' which I assume is referring to STLPort methods.

So at this point, I am simply looking for an alternative to Boost that's a bit easier to deal with in terms of compatibility.


Try using SWIG. I remember it being straight forward.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜