Boost Python类导出无法编译,visual studio 2013中出现链接错误

Boost Python类导出无法编译,visual studio 2013中出现链接错误,python,c++,boost,boost-python,Python,C++,Boost,Boost Python,我自己编译了Boost,并使用它将以下函数导出到DLL: #include <boost/python.hpp> using namespace boost::python; std::string greet() { return "hello, dude !!"; } BOOST_PYTHON_MODULE(hello) { def("greet", greet); } #包括 使用名称空间boost::python; std::string greet()

我自己编译了Boost,并使用它将以下函数导出到DLL:

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

std::string greet()
{
    return "hello, dude !!";
}

BOOST_PYTHON_MODULE(hello)
{
    def("greet", greet);
}
#包括
使用名称空间boost::python;
std::string greet()
{
回复“你好,伙计!!”;
}
BOOST_PYTHON_模块(您好)
{
def(“问候”,问候);
}
在我将hello.dll文件重命名为hello.pyd之后,它在Python中加载得很好

现在我试着这样做:

#include <boost/python.hpp>
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);
}
#包括
使用名称空间boost::python;
结构世界
{
无效集(std::string msg){this->msg=msg;}
std::string greet(){return msg;}
std::字符串msg;
};
BOOST_PYTHON_模块(您好)
{
类(“世界”)
.def(“问候语”和世界::问候语)
.def(“集”&世界::集);
}
它的错误是:

Error   29  error LNK2019: 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) referenced in function "private: virtual void * __thiscall boost::python::objects::value_holder<struct World>::holds(struct boost::python::type_info,bool)" (?holds@?$value_holder@UWorld@@@objects@python@boost@@EAEPAXUtype_info@34@_N@Z) D:\Code\Python\hello\hello\hello.obj    hello

Error   30  error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall boost::python::converter::shared_ptr_deleter::shared_ptr_deleter(struct boost::python::converter::shared_ptr_deleter const &)" (__imp_??0shared_ptr_deleter@converter@python@boost@@QAE@ABU0123@@Z) referenced in function "public: __thiscall boost::shared_ptr<void>::shared_ptr<void><void,struct boost::python::converter::shared_ptr_deleter>(void *,struct boost::python::converter::shared_ptr_deleter)" (??$?0XUshared_ptr_deleter@converter@python@boost@@@?$shared_ptr@X@boost@@QAE@PAXUshared_ptr_deleter@converter@python@1@@Z) D:\Code\Python\hello\hello\hello.obj    hello

Error   31  error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall boost::python::objects::class_base::~class_base(void)" (__imp_??1class_base@objects@python@boost@@QAE@XZ) referenced in function __unwindfunclet$??0?$class_@UWorld@@Unot_specified@detail@python@boost@@U2345@U2345@@python@boost@@QAE@PBD0@Z$0    D:\Code\Python\hello\hello\hello.obj    hello

Error   32  error LNK2019: 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) referenced in function "void __cdecl boost::python::objects::register_dynamic_id<struct World>(struct World *)" (??$register_dynamic_id@UWorld@@@objects@python@boost@@YAXPAUWorld@@@Z)  D:\Code\Python\hello\hello\hello.obj    hello
错误29错误LNK2019:未解析的外部符号“\uu declspec(dllimport)void*\uu cdecl boost::python::objects::find_static_type(void*,struct boost::python::type_info,struct boost::python::type_info)”(\uu imp_u?find_static_type@objects@python@boost@@YAPAXPAXUtype_info@23@1@Z)在函数中引用“private:virtualvoid*uu thiscall boost::python::objects::value\u holder::holds(struct boost::python::type_info,bool)”(?holds@$value)_holder@UWorld@@@objects@python@boost@@EAEPAXUtype_info@34@_N@Z)D:\Code\Python\hello\hello\hello.obj hello
错误30错误LNK2019:未解析的外部符号“\uu declspec(dllimport)public:\uu thiscall boost::python::converter::shared\u ptr\u deleter::shared\u ptr\u deleter::shared\u ptr\u deleter(struct boost::python::converter::shared\u ptr\u deleter const&”)(\uu imp\u0 shared\u ptr_deleter@converter@python@boost@@QAE@ABU0123@@Z) 在函数中引用”public:u thiscall boost::shared_ptr::shared_ptr(void*,struct boost::python::converter::shared_ptr)”_deleter@converter@python@boost@@@?$shared_ptr@X@促进@@QAE@PAXUshared_ptr_deleter@converter@python@1@@Z)D:\Code\Python\hello\hello\hello.obj hello
错误31错误LNK2019:未解析的外部符号“\uu declspec(dllimport)public:\uu thiscall boost::python::objects::class\u base::~class\u base(void)”(\uu imp\u1类_base@objects@python@boost@@QAE@XZ)在函数\uu unwindfunclet$??0?$class\uu@UWorld@@Unot中引用_specified@detail@python@boost@@U2345@U2345@@python@boost@@QAE@PBD0@Z$0 D:\Code\Python\hello\hello\hello.obj hello
错误32错误LNK2019:未解析的外部符号“\uu declspec(dllimport)void\uu cdecl boost::python::objects::register\u dynamic\u id\u aux(struct boost::python::type\u info,struct std::pair(\u cdecl*)(void*)”(\uu imp\uu?register\u dynamic\u id_aux@objects@python@boost@@亚克斯型_info@23@P6A?AU$pair@PAXUtype_info@python@boost@@@性病@@PAX@Z@Z)在函数“void\uu cdecl boost::python::objects::register\u dynamic\u id(struct World*)”中引用(??$register\u dynamic_id@UWorld@@@objects@python@boost@@YAXPAUWorld@@@Z)D:\Code\Python\hello\hello\hello.obj hello
这是Visual Studio Express 2013。我按照此处给出的确切步骤编译了自己的boost库:

我认为我的构建/安装很好,因为在此之前的全局函数很好。但是可能与MSVC 2012和13有一些不兼容,因为boost python调试库名为
boost\u python-vc120-mt-gd-1\u 56.lib

我得到了以下答案:

bjam使用下列步骤编译用于静态链接的boost:

我需要定义BOOST_PYTHON_STATIC_LIB,否则它将假定BOOST.PYTHON库的动态链接

编译以下内容的代码:

#define BOOST_PYTHON_STATIC_LIB    
#include <boost/python.hpp>
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);
}
import hello
obj = hello.World()
obj.set("Hello World!")
obj.greet()