[C++-sig] undefined symbols with def_readonly

Neal Becker ndbecker2 at gmail.com
Fri Apr 11 13:32:07 CEST 2008


Andreas Klöckner wrote:

> On Donnerstag 10 April 2008, Neal Becker wrote:
>> Stefan Seefeld wrote:
>> > Neal Becker wrote:
>> >> I have:
>> >>
>> >> struct turbo_enc_1_15 {
>> >> ...
>> >>   static const int TAIL_BITS = 2*MEMORY;
>> >> ...
>> >>
>> >> Then this wrapper:
>> >> BOOST_PYTHON_MODULE(turbo_enc_1_15)
>> >> {
>> >>   class_<turbo_enc_1_15> ("turbo_enc_1_15", no_init)
>> >> ...
>> >>     .def_readonly ("TAIL_BITS", &turbo_enc_1_15::TAIL_BITS)
>> >>     ;
>> >>
>> >> At runtime I get this:
>> >> ImportError: ../mod/turbo_enc_1_15.so: undefined symbol:
>> >> _ZN14turbo_enc_1_159TAIL_BITSE
>> >>
>> >> Anything obviously wrong here?
>> >
>> > The code above only shows the declaration of turbo_enc_1_15::TAIL_BITS,
>> > but not its definition. It seems the linker agrees with me that it is
>> > missing. (See 9.4.2/4 of the spec:
>> >
>> > "...The member shall still be defined in a namespace scope if it is
>> > used in the program..."
>> >
>> > It seems you can get away without the definition if you ever only take
>> > its value, but not its address.
>> > Note that in your code you pass the member's address to def_readonly().
>> > May be what you really want is simply add an attribute to your class,
>> > using the (compile-time evaluated) value ?
>>
>> Yes, I just want to get the (compile-time evaluated) value.  What is the
>> suggested way to do this?
> 
> You can add a static getter function and expose that. Works for me with
> the same problem: (snippet from my code)
> 
>     pic_wrap
>       .add_static_property("dimensions_pos", &cl::get_dimensions_pos)
> 
> Andreas

Didn't work here.
    .add_static_property ("TAIL_BITS", &turbo_enc_1_15::TAIL_BITS)

Still gives 
ImportError: ../mod/turbo_enc_1_15.so: undefined symbol: _ZN14turbo_enc_1_159TAIL_BITSE

But what's _really_ weird, is:
    .add_static_property ("TAIL_BITS", turbo_enc_1_15::TAIL_BITS)

gives:
TypeError: 'int' object is not callable

when that value is used.





More information about the Cplusplus-sig mailing list