Boost logo

Boost Users :

From: Jin Sun (jinsun_at_[hidden])
Date: 2007-02-06 11:01:47


I am learning boost python. I have the following code:
//test.cpp------------------------------------------------------------------
-----------------------------
#include <boost/python/module.hpp>
#include <boost/python/class.hpp>
#include <boost/python/def.hpp>
#include <boost/python/reference_existing_object.hpp>
#include <boost/python/return_value_policy.hpp>
#include <utility>

// classes to wrap
class Singleton
{
public:
    static Singleton* get_it() {return &just_one;}
    
private:
    Singleton() : x(0) {}
public:
    int exchange(int n) // set x and return the old value
    {
        std::swap(n, x);
        return n;
    }

private:
    int x;
    static Singleton just_one;
};

// Wrapper code
using namespace boost::python;
BOOST_PYTHON_MODULE(singleton)
{
    class_<Singleton, boost::noncopyable>("Singleton", no_init)
        .def("get_it", &Singleton::get_it,
 
return_value_policy<reference_existing_object>()).staticmethod("get_it")
        .def("exchange", &Singleton::exchange)
        ;
}
//--------------------------------------------------------------------------
------------------------------------------------
My Jamfile is as following:

//--------------------------------------------------------------------------
------------------------------------------------
# This is the top of our own project tree
project-root ;

# Include definitions needed for Python modules
import python ;

extension singleton # Declare a Python extension called
hello
: hello.cpp # source
    # requirements and dependencies for Boost.Python extensions
    <template>@boost/libs/python/build/extension
    ;

//--------------------------------------------------------------------------
----------------------------------------------

When I run it, I get the following error message:

Python 2.5 (r25:51908, Jan 30 2007, 15:03:58)
[GCC 4.0.2 20051125 (Red Hat 4.0.2-8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import singleton
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: ./singleton.so: undefined symbol: _ZN9Singleton8just_oneE
>>>

Can anyone help me?

Thanks!!!

Jin Sun
---------------------------------------------------------
Rekhi Hall 301
1400 Townsend Dr. Houghton MI, 49931
USA
Phone: 906-370-2261
---------------------------------------------------------


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net