boost python如何配置,python调用 C/C++

a17587060 2010-05-22 09:27:30
boost python如何配置??? 通过boost python 配置 C/C++(函数,类,类成员变量,类成员函数)的导出,
即 C/C++ 如何配置,python才能调用 C/C++
...全文
617 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
谭建新 2010-07-13
  • 打赏
  • 举报
回复
你可以去 http://www.boostpro.com/ 下载编译好的 lib和dll
a17587060 2010-06-02
  • 打赏
  • 举报
回复
谁有 boost python 配置好的源代码 工程,能否发一份给我,邮箱 a17587060@126.com, 在这里先谢谢啦
a17587060 2010-05-23
  • 打赏
  • 举报
回复
#include "boost/python.hpp"
#include "Python.h"

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>("World")
.def("greet", &World::greet)
.def("set", &World::set)
;
}



output输出:

1>RegPythonC.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall boost::python::handle<struct _object>::~handle<struct _object>(void)" (__imp_??1?$handle@U_object@@@python@boost@@QAE@XZ)
1>RegPythonC.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) struct boost::python::converter::registration const & __cdecl boost::python::converter::registry::lookup(struct boost::python::type_info)" (__imp_?lookup@registry@converter@python@boost@@YAABUregistration@234@Utype_info@34@@Z)
1>RegPythonC.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl boost::python::throw_error_already_set(void)" (__imp_?throw_error_already_set@python@boost@@YAXXZ)
1>RegPythonC.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) struct _object * __cdecl boost::python::detail::init_module(char const *,void (__cdecl*)(void))" (__imp_?init_module@detail@python@boost@@YAPAU_object@@PBDP6AXXZ@Z)
1>RegPythonC.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall boost::python::objects::class_base::class_base(char const *,unsigned int,struct boost::python::type_info const * const,char const *)" (__imp_??0class_base@objects@python@boost@@QAE@PBDIQBUtype_info@23@0@Z)
1>RegPythonC.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) protected: void __thiscall boost::python::objects::class_base::set_instance_size(unsigned int)" (__imp_?set_instance_size@class_base@objects@python@boost@@IAEXI@Z)
1>RegPythonC.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl boost::python::objects::add_to_namespace(class boost::python::api::object const &,char const *,class boost::python::api::object const &,char const *)" (__imp_?add_to_namespace@objects@python@boost@@YAXABVobject@api@23@PBD01@Z)
1>RegPythonC.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) void * __cdecl boost::python::objects::find_static_type(void *,struct boost::python::type_info,struct boost::python::type_info)" (__imp_?find_static_type@objects@python@boost@@YAPAXPAXUtype_info@23@1@Z)
1>RegPythonC.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) class boost::python::api::object __cdecl boost::python::objects::function_object(struct boost::python::objects::py_function const &,struct std::pair<struct boost::python::detail::keyword const *,struct boost::python::detail::keyword const *> const &)" (__imp_?function_object@objects@python@boost@@YA?AVobject@api@23@ABUpy_function@123@ABU?$pair@PBUkeyword@detail@python@boost@@PBU1234@@std@@@Z)
1>RegPythonC.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl boost::python::objects::copy_class_object(struct boost::python::type_info const &,struct boost::python::type_info const &)" (__imp_?copy_class_object@objects@python@boost@@YAXABUtype_info@23@0@Z)
1>RegPythonC.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl boost::python::converter::registry::insert(void * (__cdecl*)(struct _object *),void (__cdecl*)(struct _object *,struct boost::python::converter::rvalue_from_python_stage1_data *),struct boost::python::type_info,struct _typeobject const * (__cdecl*)(void))" (__imp_?insert@registry@converter@python@boost@@YAXP6APAXPAU_object@@@ZP6AX0PAUrvalue_from_python_stage1_data@234@@ZUtype_info@34@P6APBU_typeobject@@XZ@Z)
1>RegPythonC.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) void * __cdecl boost::python::converter::get_lvalue_from_python(struct _object *,struct boost::python::converter::registration const &)" (__imp_?get_lvalue_from_python@converter@python@boost@@YAPAXPAU_object@@ABUregistration@123@@Z)
1>RegPythonC.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall boost::python::converter::shared_ptr_deleter::shared_ptr_deleter(class boost::python::handle<struct _object>)" (__imp_??0shared_ptr_deleter@converter@python@boost@@QAE@V?$handle@U_object@@@23@@Z)
1>RegPythonC.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall boost::python::converter::shared_ptr_deleter::~shared_ptr_deleter(void)" (__imp_??1shared_ptr_deleter@converter@python@boost@@QAE@XZ)
1>RegPythonC.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: struct _typeobject const * __thiscall boost::python::converter::registration::expected_from_python_type(void)const " (__imp_?expected_from_python_type@registration@converter@python@boost@@QBEPBU_typeobject@@XZ)
1>RegPythonC.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl boost::python::objects::register_dynamic_id_aux(struct boost::python::type_info,struct std::pair<void *,struct boost::python::type_info> (__cdecl*)(void *))" (__imp_?register_dynamic_id_aux@objects@python@boost@@YAXUtype_info@23@P6A?AU?$pair@PAXUtype_info@python@boost@@@std@@PAX@Z@Z)
1>RegPythonC.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl boost::python::converter::registry::insert(struct _object * (__cdecl*)(void const *),struct boost::python::type_info,struct _typeobject const * (__cdecl*)(void))" (__imp_?insert@registry@converter@python@boost@@YAXP6APAU_object@@PBX@ZUtype_info@34@P6APBU_typeobject@@XZ@Z)
1>RegPythonC.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall boost::python::objects::py_function_impl_base::~py_function_impl_base(void)" (__imp_??1py_function_impl_base@objects@python@boost@@UAE@XZ)
1>RegPythonC.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) const boost::python::objects::py_function_impl_base::`vftable'" (__imp_??_7py_function_impl_base@objects@python@boost@@6B@)
1>RegPythonC.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) struct boost::python::converter::registration const * __cdecl boost::python::converter::registry::query(struct boost::python::type_info)" (__imp_?query@registry@converter@python@boost@@YAPBUregistration@234@Utype_info@34@@Z)
1>RegPythonC.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall boost::python::converter::shared_ptr_deleter::operator()(void const *)" (__imp_??Rshared_ptr_deleter@converter@python@boost@@QAEXPBX@Z)
1>RegPythonC.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall boost::python::instance_holder::install(struct _object *)" (__imp_?install@instance_holder@python@boost@@QAEXPAU_object@@@Z)
1>RegPythonC.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) struct boost::python::converter::rvalue_from_python_stage1_data __cdecl boost::python::converter::rvalue_from_python_stage1(struct _object *,struct boost::python::converter::registration const &)" (__imp_?rvalue_from_python_stage1@converter@python@boost@@YA?AUrvalue_from_python_stage1_data@123@PAU_object@@ABUregistration@123@@Z)
1>RegPythonC.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: struct _typeobject * __thiscall boost::python::converter::registration::get_class_object(void)const " (__imp_?get_class_object@registration@converter@python@boost@@QBEPAU_typeobject@@XZ)
1>RegPythonC.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall boost::python::instance_holder::instance_holder(void)" (__imp_??0instance_holder@python@boost@@QAE@XZ)
1>RegPythonC.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall boost::python::instance_holder::~instance_holder(void)" (__imp_??1instance_holder@python@boost@@UAE@XZ)
1>RegPythonC.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static void * __cdecl boost::python::instance_holder::allocate(struct _object *,unsigned int,unsigned int)" (__imp_?allocate@instance_holder@python@boost@@SAPAXPAU_object@@II@Z)
1>RegPythonC.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static void __cdecl boost::python::instance_holder::deallocate(struct _object *,void *)" (__imp_?deallocate@instance_holder@python@boost@@SAXPAU_object@@PAX@Z)
1>RegPythonC.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual unsigned int __thiscall boost::python::objects::py_function_impl_base::max_arity(void)const " (__imp_?max_arity@py_function_impl_base@objects@python@boost@@UBEIXZ)
1>RegPythonC.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall boost::python::objects::py_function






thy38 2010-05-23
  • 打赏
  • 举报
回复
boost python有什么需要配置吗?只要先加Python参数编译一下boost,然后在C++里面用就可以了。

不过Python调用C我推荐直接用标准库中的ctypes,调用C++推荐用SWIG
masterz 2010-05-23
  • 打赏
  • 举报
回复
看它的文档
http://www.boost.org/doc/libs/1_43_0/libs/python/doc/tutorial/doc/html/python/exposing.html
struct World
{
void set(std::string msg) { this->msg = msg; }
std::string greet() { return msg; }
std::string msg;
};
#include <boost/python.hpp>
using namespace boost::python;

BOOST_PYTHON_MODULE(hello)
{
class_<World>("World")
.def("greet", &World::greet)
.def("set", &World::set)
;
}
。。。
masterz 2010-05-23
  • 打赏
  • 举报
回复
你的boost.python大概没有编译好。按下面的步骤(改一下相应的目录).注意目前大多数文档/接口还是用python2.x,比如google API, 你可以考虑编译boost+python2.6
build bjam
D:\opensource\boost_1_43_0\bootstrap.bat

build boost.python
add the following to D:\opensource\boost_1_43_0\tools\build\v2\user-config.jam
###########################################################
using python
: 3.1 # Version
: C:\\Python31\\python.exe # Python Path
: C:\\Python31\\Include # include path(s) -they may be not really needed here
: C:\\Python31\\libs # lib path(s) - they may be not really needed here
: <python-debugging>off <define>BOOST_ALL_NO_LIB=1
;
using python
: 3.1 # Version
: C:\\Python31\\python.exe # Python Path
: C:\\Python31\\Include # include path(s) -they may be not really needed here
: C:\\Python31\\libs # lib path(s) - they may be not really needed here
: <python-debugging>on <define>BOOST_ALL_NO_LIB=1
;
###########################################################

call "%VS90COMNTOOLS%\..\..\vc\bin\vcvars32.bat"
cd /d D:\opensource\boost_1_43_0

REM Remove the reference to gzio on line 136 in file D:\opensource\boost_1_43_0\libs\iostreams\build\Jamfile.v2 for building with zlib-1.2.5

bjam --toolset=msvc-9.0 --build-type=complete -sBZIP2_SOURCE="D:\opensource\bzip2-1.0.5" -sZLIB_SOURCE="D:\opensource\zlib-1.2.5" -sICU_PATH="D:\opensource\icu4c-4_4_1-Win32-msvc9\icu" stage

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧