[C++-sig] Wrapping & embedding, with a segfault

David Abrahams dave at boost-consulting.com
Fri Nov 22 20:04:05 CET 2002


Vladimir Prus <ghost at cs.msu.su> writes:

> I'm trying to
> 1. Wrap some class with Boost.Python and then
> 2. Embed the Python interpreter, and run some script,
> passing the embedded class to that script.
>
> When doing 1), I've run in a problem. I've took
> the attached program, dropped it in "example" dir,
> added
>
>      exe embedding_test : embedding_test.cpp <dll>../build/boost_python   :
>          $(BOOST_PYTHON_V2_PROPERTIES) <find-library>python2.2
>       ;
>
> to Jamfile, and run "bjam". But when I run the program,
> I get segfault. What can be the problem?

There's no module initialization function, to start with. See
http://mail.python.org/pipermail/c++-sig/2002-November/002653.html,
and my followup.
>
> P.S. Please cc me, I'm not subscribed.
>
>
>
>
> // Example by Ralf W. Grosse-Kunstleve
>
> #include <iostream>
> #include <string>
>
>
>   class hello
>   {
>     public:
>       hello(const std::string& country) { this->country = country; }
>       std::string greet() const { return "Hello from " + country; }
>     private:
>       std::string country;
>   };
>
>
> #include <boost/python/class.hpp>
> #include <boost/python/module.hpp>
> #include <boost/python/def.hpp>
>
> int main()
> {
>     using namespace boost::python;
>     class_<hello> d("hello", init<std::string>());
>     
>         // Add a regular member function.
>         d.def("greet", &hello::greet);
>
> 	
>     cout << d.ptr() << "\n";	
> }	
>     
>

-- 
                       David Abrahams
   dave at boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution





More information about the Cplusplus-sig mailing list