Boost logo

Boost :

From: Philippe Vaucher (philippe.vaucher_at_[hidden])
Date: 2007-07-23 09:29:40


Hi guys,

Is boost::python supposed to work with msvc2005 ?

I took the hello world from "embedding python" and "error_already_set" is
being thrown at me...

Here's the code I used :

#include <iostream>
#include <string>

#include <boost/python.hpp>

using namespace boost::python;

void greet()
{
  Py_Initialize();

  // 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(self): \n"
    " return 'Hello from Python!' \n",
    global, global);

  // Create a reference to it.
  object greet = global["greet"];

  // Call it.
  std::string message = extract<std::string>(greet());
  std::cout << message << std::endl;

  Py_Finalize();
}

int main()
{
    greet();
    return 0;
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk