
You must initilize the static variable:
#include
I am learning boost python. I have the following code: //test.cpp------------------------------------------------------------------ ----------------------------- #include
#include #include #include #include #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", no_init) .def("get_it", &Singleton::get_it, return_value_policy
()).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 mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
With Kind Regards, Ovanes Markarian