Вот файл world.cpp.
Код: Выделить всё
#include
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(world_ext)
{
using namespace boost::python;
class_("World")
.def("greet", &World::greet)
.def("set", &World::set)
;
}
Код: Выделить всё
# Copyright Stefan Seefeld 2016.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
import python ;
project tutorial
: requirements
.
;
# ------ for hello
#python-extension hello_ext : hello.cpp ;
#
#run-test hello : hello_ext hello.py ;
#
#alias test : hello ;
#explicit test ;
# ------ for world
python-extension world_ext : world.cpp ;
run-test world : world_ext world.py ;
alias test : world ;
explicit test ;
Код: Выделить всё
...found 11 targets...
...updating 4 targets...
gcc.compile.c++ world.o
world.cpp: In function 'void init_module_world_ext()':
world.cpp:20:17: error: wrong number of template arguments (1, should be 4)
class_("World")
^
In file included from /usr/local/include/boost/python/object_core.hpp:20:0,
from /usr/local/include/boost/python/args.hpp:22,
from /usr/local/include/boost/python/make_function.hpp:11,
from /usr/local/include/boost/python/def.hpp:11,
from world.cpp:8:
/usr/local/include/boost/python/def_visitor.hpp:14:56: note: provided for 'template class boost::python::class_'
template class class_;
^
"g++" -fPIC -O0 -fno-inline -Wall -g -I"/usr/include/python3.5" -c -o "world.o" "world.cpp"
...failed gcc.compile.c++ world.o...
...skipped
world_ext.so for lack of world.o...
...skipped world for lack of world_ext.so...
...failed updating 1 target...
...skipped 3 targets...
Код: Выделить всё
hello
Похоже, это касается раскрытия классов. Ему требуется 4 параметра шаблона, но исходный код руководства дает только один. Что я должен делать? (кстати, я надеюсь, что специалисты по поддержке обновят руководства для текущей версии Boost с более любезными объяснениями. Между документами и выпущенным кодом много расхождений.)
Подробнее здесь: https://stackoverflow.com/questions/638 ... plate-argu