在Visual Studio 2005中轻松获得Python中的c++扩展
Painless way to get C++ extensions in Python in Visual Studio 2005
我在STLPort 5.1.0和Boot中遇到了一些非常严重的兼容性问题。Python 1.46.1在Visual Studio 2005中,我想知道是否有任何其他方法让Python调用c++代码。
万一有人能帮忙:下面的代码编译和运行没有问题:Char const* greet(){返回"hello, world";}
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的替代方案,它在兼容性方面更容易处理。
尝试使用SWIG。
相关文章:
- Python中的for循环与C++有何不同
- 如何通过 pybind11 从 python 中的C++中捕获异常?
- C++ python 中的函数返回数字而不是字符串
- C++和 Python 中的代码相同,但输出不同
- 你如何决定将C++和/或 python 中的成员函数表示为静态?
- 了解 Python 中的对象类型
- 如何创建一个接口,允许我访问C++中的按钮(和其他ui)函数,该函数是使用python中的MFC实现的
- 如何使用 SWIG 接口访问 python 中的 C++ typedef'd 结构
- 方法 argv[] SWIG C++ / Python 中的错误,会发生什么?
- Python中的反向无符号字符
- python中的正则表达式删除了太多
- 用于Ctypes的Python中的Safearray
- 如何在python中的PyArrow和C++中的Arrow之间进行交互时将PyArrow表转换为Arrow表
- 使用 boost python 从 c++ 为 python 中的类成员变量赋值
- Python中的C 载体
- 我如何在C++中使用某种方法来替换 python 中的 isdisjoint
- 在Pybind11中使用Python中的C 对象
- C++ python 中的函数来自使用 ctypes 的.dll - 找不到函数和访问冲突
- 如何将 Python 中的字节对象传递给用 Swig 包装的C++函数
- Python中的不确定行为