Boost-Python-Beispiel "Hello World" in Python

Ich habe große Schwierigkeiten mit meinem c++ - code Visual C++ (umhüllt von boost) in Python.

Ordnung, also die Werkzeuge, die ich verwende sind: Visual Studio 2010, BoostPro 1_47, Windows 7 und Python 2.7 (32-bit).

Ich habe folgenden code, der kompiliert schön in Visual Studio 2010:

#define BOOST_PYTHON_STATIC_LIB
#include <boost/python.hpp>
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(hello)
{
    class_<World>("World")
            .def("greet", &World::greet)
            .def("set", &World::set);
}

Es ist im format: "Win32 Console Application" >>>Leeres Projekt /DLL.

In Der "Projekt-Eigenschaften":

VC++ DIRECTORIES: 
  I added:  
  >>> INCLUDE DIRECTORIES:  C:\Program Files\boost\boost_1_47;C:\Python27\include        .  
  >>> LIBRARY DIRECTORIES:  C:\Program Files\boost\boost_1_47\lib;C:\Python27\libs

All dies macht die c++ - Datei erstellen, aber dann kann ich nicht darauf zugreifen von Python.

Dies ist, was Python sagt, wenn ich versuche, das Modul:

">>> import hello
 Traceback (most recent call last):
   File "<pyshell#0>", line 1, in <module>
     import hello
 ImportError: No module named hello

Also ich denke, meine Frage ist... Wie bekomme ich Python, um es zu finden???

Wenn der c++ code kompiliert werden, erstellt er eine DLL-Datei. Muss ich zum ändern des Speicherorts der Datei? Wenn ja, wo sollte ich es sagen?

Ihre Hilfe würde sehr geschätzt werden

InformationsquelleAutor user1449530 | 2012-06-14
Schreibe einen Kommentar