首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用docstring_options公开类时出现boost.python MSVC12链接器错误

使用docstring_options公开类时出现boost.python MSVC12链接器错误
EN

Stack Overflow用户
提问于 2017-02-16 00:17:04
回答 1查看 83关注 0票数 0

我经常使用boost.python &MSVC12(动态链接)将c++类暴露给python。最近,我一直在尝试使用"docstring_options“类包含文档。文档示例运行良好:

http://www.boost.org/doc/libs/1_54_0/libs/python/doc/v2/docstring_options.html

然而,当我包含一个类并公开它时,我得到了链接器错误:

错误函数:未解析的外部符号“(?throw_exception@boost@@YAXABVexception@std@@@Z) __cdecl boost::throw_exception((?throw_exception@boost@@YAXABVexception@std@@@Z) std::exception const &)”在函数中引用的公共: boost::detail::shared_count::shared_count(void boost::python::converter::shared_ptr_deleter)“*,结构__thiscall

我确信我可能遗漏了一些简单的东西,但是我想不出来。

首先要感谢大家!

从boost示例中拼接的示例代码为我提供了此错误。

代码语言:javascript
复制
#include <string>
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
#include <boost/python/args.hpp>
#include <boost/python/docstring_options.hpp>
#include <boost/python.hpp>
struct World
{
void set(std::string msg) { this->msg = msg; }
std::string greet() { return msg; }
std::string msg;
};
int foo1(int i) { return i; }
int foo2(long l) { return static_cast<int>(l); }
int bar1(int i) { return i; }
int bar2(long l) { return static_cast<int>(l); }
namespace {
void wrap_foos()
{
    using namespace boost::python;
    def("foo1", foo1, arg("i"), "foo1 doc");
    def("foo2", foo2, arg("l"), "foo2 doc");
}
void wrap_bars()
{
    using namespace boost::python;
    bool show_user_defined = true;
    bool show_signatures = false;
    docstring_options doc_options(show_user_defined, show_signatures);
    def("bar1", bar1, arg("i"), "bar1 doc");
    def("bar2", bar2, arg("l"), "bar2 doc");

    class_<World>("World")
        .def("greet", &World::greet)
        .def("set", &World::set)
    ;

}
}
BOOST_PYTHON_MODULE(boost_py_doc_demo)
{
boost::python::docstring_options doc_options(false);
wrap_foos();
wrap_bars();
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-09 23:22:20

我编译了boost的最新版本(1.63),现在这个问题已经解决了。我猜我的旧库在某种程度上是不完整的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42254646

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档