无痛获得 C++ 的方法Visual Studio 2005 中的 Python 扩展
我在 Visual Studio 2005 中遇到了一些与 STLPort 5.1.0 和 Boot.Python 1.46.1 非常严重的兼容性问题,我想知道是否有其他方法可以让 Python 调用 C++ 代码。
以防万一有人可以提供帮助: 以下代码编译并运行没有问题: char const* 问候() { 返回“你好,世界”; 不幸
BOOST_PYTHON_MODULE(hello_ext)
{
using namespace boost::python;
def("greet", greet);
}
当我做一些稍微复杂的事情时,链接错误就会开始:
#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)
;
}
的是,我非常沮丧,我已经将我的代码破坏到可以重现链接错误的程度,因为出现了其他编译错误。但这些错误是以“stlp”开头的未定义符号的链接错误,我认为它指的是 STLPort 方法。
所以在这一点上,我只是在寻找 Boost 的替代方案,在兼容性方面更容易处理。
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 linking 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用 SWIG。我记得它是直截了当的。
Try using SWIG. I remember it being straight forward.