[C++-sig] undefined symbols with def_readonly

Stefan Seefeld seefeld at sympatico.ca
Thu Apr 10 14:44:44 CEST 2008


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 ?


Regards,
		Stefan

-- 

       ...ich hab' noch einen Koffer in Berlin...



More information about the Cplusplus-sig mailing list