【发布时间】:2015-08-18 19:38:13
【问题描述】:
我想扩展我的 C++ 应用程序以包含 Python 解释器。经过一段时间的研究,boost.python 似乎是我想要的。但不知何故,我无法让它工作。基本上我想用我的 C++ 应用程序加载和执行 Python 脚本。我将传递 PyEditor 类的实例,然后脚本可以调用各种方法。我使用回调机制来通知脚本更改。
现在我无法编译我的代码。它一直告诉我
libs/boost-1.5.8/boost/python/module_init.hpp:79:8: error: expected unqualified-id before string constant extern "C" __attribute__ ((__visibility__("default"))) _BOOST_PYTHON_MODULE_INIT(name) libs/boost-1.5.8/boost/python/module.hpp:11:30: note: in expansion of macro ‘BOOST_PYTHON_MODULE_INIT’ # define BOOST_PYTHON_MODULE BOOST_PYTHON_MODULE_INIT
这是我加载脚本的函数
void PythonManager::LoadModules()
{
BOOST_PYTHON_MODULE(PyManager)
{
boost::python::class_<PyEditor>("PyEditor", boost::python::no_init)
.def("GetText",&PyEditor::GetText)
.def("GetText",&PyEditor::SetText)
.def("AddCallable",&PyEditor::AddCallable);
}
PyImport_AppendInittab("PyManager");
Py_Initialize();
boost::python::object pyManagerModule((handle<>(PyImport_ImportModule("PyManager"))));
main_namespace["PyManager"] = pyManagerModule;
scope(cpp_module).attr("editor") = boost::python::ptr(new PyEditor());
//Load the .py files
}
我已经阅读了几乎所有可以阅读的资源,但我无法理解我的错误
【问题讨论】:
-
哪些编译器/库版本?
-
编译器是 GCC 4.8 和 boost 1.5.8
标签: python c++ python-3.x boost boost-python