我正在尝试Boost.Python演示,
使用envs:
Boost 1.66.0 src install
sudo apt install python3-dev build-essential
./bootstrap.sh --with-python=python3.5
./b2
sudo ./b2 install
进行演示时:
#include <boost/parameter/keyword.hpp>
#include <boost/parameter/preprocessor.hpp>
#include <boost/parameter/python.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/python.hpp>
// First the keywords
BOOST_PARAMETER_KEYWORD(tag, title)
BOOST_PARAMETER_KEYWORD(tag, width)
BOOST_PARAMETER_KEYWORD(tag, height)
class window
{
public:
BOOST_PARAMETER_MEMBER_FUNCTION(
(void), open, tag,
(required (title, (std::string))
(optional (width, (unsigned), 400) (height, (unsigned), 400))
)
{
printf("Open An New Windows %s of Width %u & height %u \n", title, width, height);
}
};
struct open_fwd
{
template <class A0, class A1, class A2>
void operator()( boost::type<void>, window& self, A0 const& a0, A1 const& a1, A2 const& a2 )
{
self.open(a0, a1, a2);
}
};
BOOST_PYTHON_MODULE(my_module)
{
using namespace boost::python;
namespace py = boost::parameter::python;
namespace mpl = boost::mpl;
class_<window>("window")
.def(
"open", py::function<
open_fwd
, mpl::vector<
void
, tag::title(std::string)
, tag::width*(unsigned)
, tag::height*(unsigned)
>
>()
);
}
我得到了输出:
parameter.cpp:52:0: error: unterminated argument list invoking macro "BOOST_PARAMETER_MEMBER_FUNCTION"
}
^
In file included from parameter.cpp:3:0:
/usr/local/include/boost/parameter/python.hpp: In function ‘PyObject* boost::parameter::python::aux::unspecified_type()’:
/usr/local/include/boost/parameter/python.hpp:66:7: error: invalid conversion from ‘const char*’ to ‘Py_ssize_t {aka long int}’ [-fpermissive]
};
^
/usr/local/include/boost/parameter/python.hpp:66:7: error: invalid conversion from ‘long unsigned int’ to ‘const char*’ [-fpermissive]
/usr/local/include/boost/parameter/python.hpp:68:23: error: ‘PyTypeObject {aka struct _typeobject}’ has no member named ‘ob_type’
if (unspecified.ob_type == 0)
^
/usr/local/include/boost/parameter/python.hpp:70:23: error: ‘PyTypeObject {aka struct _typeobject}’ has no member named ‘ob_type’
unspecified.ob_type = &PyType_Type;
^
parameter.cpp: At global scope:
parameter.cpp:15:5: error: ‘BOOST_PARAMETER_MEMBER_FUNCTION’ does not name a type
BOOST_PARAMETER_MEMBER_FUNCTION(
^
parameter.cpp:15:5: error: expected ‘}’ at end of input
parameter.cpp:15:5: error: expected unqualified-id at end of input
问题是,如何解决“'PyTypeObject {aka struct _typeobject}'没有名为'ob_type'的成员”错误。