Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <boost/Python.h>
- float func( int a )
- {
- return a*a-0.5;
- }
- BOOST_PYTHON_MODULE(test_module)
- {
- using namespace boost::python;
- def("func", func);
- }
- int main()
- {
- //Try one
- boost::python::exec("b = 5");
- //Crash
- //Try two
- Py_Initialize();
- boost::python::exec("b = 5");
- //Works fine
- //Try three
- Py_Initialize();
- boost::python::exec("import test_module");
- //Throws boost::python::error_already_set and crashes
- /*
- Something along the lines of
- boost::python::exec("import test_module\n"
- "var = test_module.func( 3 )\n");
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement