Hi,
I'm very new to boost, and I first want to thank you all for the hard and impressive work that has been done.
I'm currently trying to use Boost.python and I'm facing an annoying issue.
The following source code compiles fine (with msvc10 and mingw gcc 4.7):
#include
#include <iostream>
using namespace boost::python;
void greet()
{
// Retrieve the main module.
object main = import("__main__");
// Retrieve the main module's namespace
object global(main.attr("__dict__"));
// Define greet function in Python.
object result = exec("def greet():\n" " return 'Hello from Python!' \n", global, global);
// Create a reference to it.
object greet = global["greet"];
// Call it.
std::string message = extractstd::string(greet());
std::cout << message << std::endl;
}
void greet_file()
{
// Retrieve the main module.
object main = import("__main__");
// Retrieve the main module's namespace
object global(main.attr("__dict__"));
// Define greet function in Python.
object result = exec_file("hello.py", global, global);
// Create a reference to it.
object greet = global["greet"];
// Call it.
std::string message = extractstd::string(greet());
std::cout << message << std::endl;
}
void main(int argc, char** argv)
{
Py_Initialize();
greet();
greet_file();
}
It even runs perfectly well when I'm using boost.python linked against python 2.7.3 library. I have following output:
Hello from Python!
Hello from Python!
The issue appears when I link boost.python against python 3.2 (tried with 3.2.2 and 3.2.3)
the first 'Hello from Python!' shows up, but then it crashes and all I can see is a windows message box saying 'prog.exe has stopped working'.
It's not that I absolutely want to use python 3, but as I'm working on a new project, I'm concerned with durability, so I would prefer 3.2.
Any idea would be welcome.
Thanks for reading.
Yannick.