On 21/05/2010, at 8:05 PM, Brian O'Kennedy wrote:
Hi,
I'm wrapping a very simple class using PyPlusPlus.
---- snip ----
class testclass
{
public:
static const int a = 99;
};
---- /snip ----
And Py++ exposes the static member with a def_readonly("a",
testclass::a ) call. When I import this module into python I get an
undefined symbol for testclass::a.
ImportError: ./testwrapper.so: undefined symbol: _ZN9testclass1aE
I understand that the static member has no storage and thus boost
python cannot find the address of it.
I think your understanding of static member has no storage is not
really correct. What I think is, you have
declaration of 'a' but no definition of it. There is no linkage error
unless you reference 'a'. The reason is
static const data member of integral type initialized with a constant
value is treated as a constant expression.
So it means it is ok to use 'a' as a constant in your C++ code, but
when you reference it in runtime, you need
the definition of it, which in your example, you don't have.
In your wrapper code put something like this:
const int testclass:a;
HTH,
Kun
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig