Note that there are some explanatory texts on larger screens.

plurals
  1. POBoost Python Hello World example not working in Python
    primarykey
    data
    text
    <p>I'm having a great deal of trouble using my c++ code from Visual C++ (wrapped by boost) in Python.</p> <p>Alright, so the tools I'm using are: Visual Studio 2010, BoostPro 1_47, Windows 7, and Python 2.7 (32-bit). </p> <p>I have the following code which compiles nicely in Visual Studio 2010:</p> <pre><code>#define BOOST_PYTHON_STATIC_LIB #include &lt;boost/python.hpp&gt; using namespace boost::python; struct World { void set(std::string msg) { this-&gt;msg = msg; } std::string greet() { return msg; } std::string msg; }; BOOST_PYTHON_MODULE(hello) { class_&lt;World&gt;("World") .def("greet", &amp;World::greet) .def("set", &amp;World::set); } </code></pre> <p>It's in the format: Win32 Console Application >>>Empty Project / DLL.</p> <p>In "Project Properties":</p> <pre><code>VC++ DIRECTORIES: I added: &gt;&gt;&gt; INCLUDE DIRECTORIES: C:\Program Files\boost\boost_1_47;C:\Python27\include . &gt;&gt;&gt; LIBRARY DIRECTORIES: C:\Program Files\boost\boost_1_47\lib;C:\Python27\libs </code></pre> <p>All of this makes the c++ file build but then I can't access it from Python. </p> <p>This is what Python says when I try to use the module:</p> <pre><code>"&gt;&gt;&gt; import hello Traceback (most recent call last): File "&lt;pyshell#0&gt;", line 1, in &lt;module&gt; import hello ImportError: No module named hello </code></pre> <p>So I guess my question is... How can I get Python to find it???</p> <p>When the c++ code compiles it creates a DLL file. Do I have to change the location of the file? If so, where should I put it?</p> <p>Your help would be greatly appreciated</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload