1

我正在尝试为 python 创建 C++ 扩展。我的 C++ 代码依赖于 STLPort 5.1.0。我已经用 stdlib=stlport 编译了 boost.python。这发生在我的编译器 Microsoft Visual Studio 2005 中。

但是当我尝试编译我的测试项目时,我不断收到以下链接错误。

stdafx.h 包含:

// STL
#include <string>
#include <fstream>
#include <sstream>
#include <vector>
#include <iostream>
using namespace std;

// Boost
#include <boost/shared_ptr.hpp>
#include <boost/algorithm/string.hpp>
#define BOOST_PYTHON_STATIC_LIB

TestProject.cpp: #include "stdafx.h" #include "TestProject.h"

/**Python Link Begin**/
#include <boost/python.hpp>
#include <boost/random.hpp>
#include <boost/random/normal_distribution.hpp>

using namespace boost::python;

boost::mt19937 gen;
struct World
{
    std::string msg;
    double mypi;

    World(std::string msg): msg(msg) {
        gen.seed(std::time(0));
    } // 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; }

    double getgaussrand() {
        boost::normal_distribution<> nd(0.0, 1.0);
        boost::variate_generator<boost::mt19937&, boost::normal_distribution<> > var_nor(gen, nd);
        return var_nor();
    }

};

BOOST_PYTHON_MODULE(TestProject)
{
    class_<World>("World", init<std::string>())
        .def("greet", &World::greet)
        .def("set", &World::set)
        .def("getgaussrand", &World::getgaussrand)
        .def_readonly("msg",  &World::msg)
        .def_readwrite("mypi", &World::mypi)
        .add_property("rovalue", &World::get)
        .add_property("value", &World::get, &World::setter)
    ;
}

最重要的是,以下链接错误结果:错误 2 错误 LNK2019:未解析的外部符号“class boost::python::api::object __cdecl boost::python::objects::function_object(struct boost::python::objects: :py_function const &,struct stlpd_std::pair const &)" (?function_object@objects@python@boost@@YA?AVobject@api@23@ABUpy_function@123@ABU?$pair@PBUkeyword@detail@python@boost@ @PBU1234@@stlpd_std@@@Z) 在函数 "class boost::python::api::object __cdecl boost::python::detail::make_function_aux,class stlpd_std::allocator > (__thiscall World::*) 中引用(void),struct boost::python::default_call_policies,struct boost::mpl::vector2,class stlpd_std::allocator >,struct World &>,struct boost::mpl::int_<0> >(class stlpd_std: :basic_string,class stlpd_std::allocator > (__thiscall World::*)(void),struct boost::python::default_call_policies const &,struct boost::mpl::vector2,class stlpd_std::allocator >,struct World &> const &,struct stlpd_std::pair const &,struct boost ::mpl::int_<0>)" (??$make_function_aux@P8World@@AE?AV?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@ XZUdefault_call_policies@python@boost@@U?$vector2@V?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@AAUWorld@@@mpl@6@U? $int_@$0A@@86@@detail@python@boost@@YA?AVobject@api@12@P8World@@AE?AV?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@ D@2@@stlpd_std@@XZABUdefault_call_policies@12@ABU?$vector2@V?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@AAUWorld@@@mpl @2@ABU?$pair@PBUkeyword@detail@python@boost@@PBU1234@@7@U?$int_@$0A@@mpl@2@@Z) TestProject.objstruct boost::python::default_call_policies const &,struct boost::mpl::vector2,class stlpd_std::allocator >,struct World &> const &,struct stlpd_std::pair const &,struct boost::mpl::int_ <0>)" (??$make_function_aux@P8World@@AE?AV?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@XZUdefault_call_policies@python@boost@ @U?$vector2@V?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@AAUWorld@@@mpl@6@U?$int_@$0A@ @86@@detail@python@boost@@YA?AVobject@api@12@P8World@@AE?AV?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std @@XZABUdefault_call_policies@12@ABU?$vector2@V?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@AAUWorld@@@mpl@2@ABU?$ pair@PBUkeyword@detail@python@boost@@PBU1234@@7@U?$int_@$0A@@mpl@2@@Z) TestProject.objstruct boost::python::default_call_policies const &,struct boost::mpl::vector2,class stlpd_std::allocator >,struct World &> const &,struct stlpd_std::pair const &,struct boost::mpl::int_ <0>)" (??$make_function_aux@P8World@@AE?AV?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@XZUdefault_call_policies@python@boost@ @U?$vector2@V?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@AAUWorld@@@mpl@6@U?$int_@$0A@ @86@@detail@python@boost@@YA?AVobject@api@12@P8World@@AE?AV?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std @@XZABUdefault_call_policies@12@ABU?$vector2@V?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@AAUWorld@@@mpl@2@ABU?$ pair@PBUkeyword@detail@python@boost@@PBU1234@@7@U?$int_@$0A@@mpl@2@@Z) TestProject.objpython::default_call_policies const &,struct boost::mpl::vector2,class stlpd_std::allocator >,struct World &> const &,struct stlpd_std::pair const &,struct boost::mpl::int_<0>) " (??$make_function_aux@P8World@@AE?AV?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@XZUdefault_call_policies@python@boost@@U?$ vector2@V?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@AAUWorld@@@mpl@6@U?$int_@$0A@@86@@ detail@python@boost@@YA?AVobject@api@12@P8World@@AE?AV?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@XZABUdefault_call_policies@ 12@ABU?$vector2@V?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@AAUWorld@@@mpl@2@ABU?$pair@PBUkeyword@ detail@python@boost@@PBU1234@@7@U?$int_@$0A@@mpl@2@@Z) TestProject.objpython::default_call_policies const &,struct boost::mpl::vector2,class stlpd_std::allocator >,struct World &> const &,struct stlpd_std::pair const &,struct boost::mpl::int_<0>) " (??$make_function_aux@P8World@@AE?AV?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@XZUdefault_call_policies@python@boost@@U?$ vector2@V?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@AAUWorld@@@mpl@6@U?$int_@$0A@@86@@ detail@python@boost@@YA?AVobject@api@12@P8World@@AE?AV?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@XZABUdefault_call_policies@ 12@ABU?$vector2@V?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@AAUWorld@@@mpl@2@ABU?$pair@PBUkeyword@ detail@python@boost@@PBU1234@@7@U?$int_@$0A@@mpl@2@@Z) TestProject.objdefault_call_policies const &,struct boost::mpl::vector2,class stlpd_std::allocator >,struct World &> const &,struct stlpd_std::pair const &,struct boost::mpl::int_<0>)" (? ?$make_function_aux@P8World@@AE?AV?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@XZUdefault_call_policies@python@boost@@U?$vector2@V ?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@AAUWorld@@@mpl@6@U?$int_@$0A@@86@@detail@python @boost@@YA?AVobject@api@12@P8World@@AE?AV?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@XZABUdefault_call_policies@12@ABU ?$vector2@V?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@AAUWorld@@@mpl@2@ABU?$pair@PBUkeyword@detail@python @boost@@PBU1234@@7@U?$int_@$0A@@mpl@2@@Z) TestProject.objdefault_call_policies const &,struct boost::mpl::vector2,class stlpd_std::allocator >,struct World &> const &,struct stlpd_std::pair const &,struct boost::mpl::int_<0>)" (? ?$make_function_aux@P8World@@AE?AV?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@XZUdefault_call_policies@python@boost@@U?$vector2@V ?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@AAUWorld@@@mpl@6@U?$int_@$0A@@86@@detail@python @boost@@YA?AVobject@api@12@P8World@@AE?AV?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@XZABUdefault_call_policies@12@ABU ?$vector2@V?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@AAUWorld@@@mpl@2@ABU?$pair@PBUkeyword@detail@python @boost@@PBU1234@@7@U?$int_@$0A@@mpl@2@@Z) TestProject.objvector2,class stlpd_std::allocator >,struct World &> const &,struct stlpd_std::pair const &,struct boost::mpl::int_<0>)" (??$make_function_aux@P8World@@AE?AV? $basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@XZUdefault_call_policies@python@boost@@U?$vector2@V?$basic_string@DV?$char_traits@D@ stlpd_std@@V?$allocator@D@2@@stlpd_std@@AAUWorld@@@mpl@6@U?$int_@$0A@@86@@detail@python@boost@@YA?AVobject@api@12 @P8World@@AE?AV?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@XZABUdefault_call_policies@12@ABU?$vector2@V?$basic_string@DV? $char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@AAUWorld@@@mpl@2@ABU?$pair@PBUkeyword@detail@python@boost@@PBU1234@@7@U? $int_@$0A@@mpl@2@@Z) TestProject.objvector2,class stlpd_std::allocator >,struct World &> const &,struct stlpd_std::pair const &,struct boost::mpl::int_<0>)" (??$make_function_aux@P8World@@AE?AV? $basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@XZUdefault_call_policies@python@boost@@U?$vector2@V?$basic_string@DV?$char_traits@D@ stlpd_std@@V?$allocator@D@2@@stlpd_std@@AAUWorld@@@mpl@6@U?$int_@$0A@@86@@detail@python@boost@@YA?AVobject@api@12 @P8World@@AE?AV?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@XZABUdefault_call_policies@12@ABU?$vector2@V?$basic_string@DV? $char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@AAUWorld@@@mpl@2@ABU?$pair@PBUkeyword@detail@python@boost@@PBU1234@@7@U? $int_@$0A@@mpl@2@@Z) TestProject.objpair const &,struct boost::mpl::int_<0>)" (??$make_function_aux@P8World@@AE?AV?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@ 2@@stlpd_std@@XZUdefault_call_policies@python@boost@@U?$vector2@V?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@AAUWorld@@@ mpl@6@U?$int_@$0A@@86@@detail@python@boost@@YA?AVobject@api@12@P8World@@AE?AV?$basic_string@DV?$char_traits@D@stlpd_std@ @V?$allocator@D@2@@stlpd_std@@XZABUdefault_call_policies@12@ABU?$vector2@V?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@ @AAUWorld@@@mpl@2@ABU?$pair@PBUkeyword@detail@python@boost@@PBU1234@@7@U?$int_@$0A@@mpl@2@@Z) TestProject.objpair const &,struct boost::mpl::int_<0>)" (??$make_function_aux@P8World@@AE?AV?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@ 2@@stlpd_std@@XZUdefault_call_policies@python@boost@@U?$vector2@V?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@AAUWorld@@@ mpl@6@U?$int_@$0A@@86@@detail@python@boost@@YA?AVobject@api@12@P8World@@AE?AV?$basic_string@DV?$char_traits@D@stlpd_std@ @V?$allocator@D@2@@stlpd_std@@XZABUdefault_call_policies@12@ABU?$vector2@V?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@ @AAUWorld@@@mpl@2@ABU?$pair@PBUkeyword@detail@python@boost@@PBU1234@@7@U?$int_@$0A@@mpl@2@@Z) TestProject.obj(??$make_function_aux@P8World@@AE?AV?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@XZUdefault_call_policies@python@boost@@U?$vector2 @V?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@AAUWorld@@@mpl@6@U?$int_@$0A@@86@@detail @python@boost@@YA?AVobject@api@12@P8World@@AE?AV?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@XZABUdefault_call_policies@12 @ABU?$vector2@V?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@AAUWorld@@@mpl@2@ABU?$pair@PBUkeyword@detail @python@boost@@PBU1234@@7@U?$int_@$0A@@mpl@2@@Z) TestProject.obj(??$make_function_aux@P8World@@AE?AV?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@XZUdefault_call_policies@python@boost@@U?$vector2 @V?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@AAUWorld@@@mpl@6@U?$int_@$0A@@86@@detail @python@boost@@YA?AVobject@api@12@P8World@@AE?AV?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@XZABUdefault_call_policies@12 @ABU?$vector2@V?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@AAUWorld@@@mpl@2@ABU?$pair@PBUkeyword@detail @python@boost@@PBU1234@@7@U?$int_@$0A@@mpl@2@@Z) TestProject.obj对象对象

4

1 回答 1

0

If I remember correctly, the Boost Python library requires you to build it ahead of time so that your projects that use it can link against it. Have you done this already?

于 2011-04-18T20:56:32.137 回答