List Info

Thread: undefined symbols with def_readonly




undefined symbols with def_readonly
country flaguser name
United States
2008-04-10 07:09:25
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?

_______________________________________________
C++-sig mailing list
C++-sigpython.org
http:
//mail.python.org/mailman/listinfo/c++-sig

Re: undefined symbols with def_readonly
country flaguser name
United States
2008-04-10 07:44:44
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...
_______________________________________________
C++-sig mailing list
C++-sigpython.org
http:
//mail.python.org/mailman/listinfo/c++-sig

Re: undefined symbols with def_readonly
country flaguser name
United States
2008-04-10 08:03:19
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?


_______________________________________________
C++-sig mailing list
C++-sigpython.org
http:
//mail.python.org/mailman/listinfo/c++-sig

Re: undefined symbols with def_readonly
country flaguser name
United States
2008-04-10 08:07:57
Neal Becker wrote:

>>>   class_<turbo_enc_1_15>
("turbo_enc_1_15", no_init)
>>> ...
>>>     .def_readonly ("TAIL_BITS",
&turbo_enc_1_15::TAIL_BITS)

[...]

> Yes, I just want to get the (compile-time evaluated)
value.  What is the
> suggested way to do this?

Try

.def_readonly ("TAIL_BITS",
turbo_enc_1_15::TAIL_BITS)


(i.e. without the address-of operator). If that doesn't
work, simply set 
a raw attribute:

.setattr ("TAIL_BITS", turbo_enc_1_15::TAIL_BITS)

HTH,
		Stefan

-- 

       ...ich hab' noch einen Koffer in Berlin...
_______________________________________________
C++-sig mailing list
C++-sigpython.org
http:
//mail.python.org/mailman/listinfo/c++-sig

Re: undefined symbols with def_readonly
country flaguser name
United States
2008-04-10 08:27:53
Stefan Seefeld wrote:

> Neal Becker wrote:
> 
>>>>   class_<turbo_enc_1_15>
("turbo_enc_1_15", no_init)
>>>> ...
>>>>     .def_readonly ("TAIL_BITS",
&turbo_enc_1_15::TAIL_BITS)
> 
> [...]
> 
>> Yes, I just want to get the (compile-time
evaluated) value.  What is the
>> suggested way to do this?
> 
> Try
> 
> .def_readonly ("TAIL_BITS",
turbo_enc_1_15::TAIL_BITS)
> 
> 
> (i.e. without the address-of operator). If that doesn't
work, simply set
> a raw attribute:
> 
> .setattr ("TAIL_BITS",
turbo_enc_1_15::TAIL_BITS)
> 
> HTH,
> Stefan
> 

Surprisingly, this still doesn't work:
...
    .setattr ("TAIL_BITS",
turbo_enc_1_15::TAIL_BITS)

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

_______________________________________________
C++-sig mailing list
C++-sigpython.org
http:
//mail.python.org/mailman/listinfo/c++-sig

Re: undefined symbols with def_readonly
country flaguser name
United States
2008-04-10 08:35:12
Neal Becker wrote:

> Surprisingly, this still doesn't work:
> ...
>     .setattr ("TAIL_BITS",
turbo_enc_1_15::TAIL_BITS)
> 
> ImportError: ../mod/turbo_enc_1_15.so: undefined
symbol: _ZN14turbo_enc_1_159TAIL_BITSE

And this:

int const tail_bits = turbo_enc_1_15::TAIL_BITS;

...
.setattr("TAIL_BITS", tail_bits)

?

Note that the class_<>::setattr() method still takes a
reference of its 
second argument, which, if the compiler doesn't optimize it
away, emits 
a symbol reference. So, introducing this local 'tail_bits'
variable has 
basically the same effect as defining
turbo_enc_1_15::TAIL_BITS. The 
latter would obviously be the more proper solution to your
problem, but 
if you don't want or can't do that, such a local variable
may be a 
viable workaround. (Not sure how portable it is, though.)

Regards,
		Stefan

-- 

       ...ich hab' noch einen Koffer in Berlin...
_______________________________________________
C++-sig mailing list
C++-sigpython.org
http:
//mail.python.org/mailman/listinfo/c++-sig

Re: undefined symbols with def_readonly
user name
2008-04-10 08:43:48
On Thu, Apr 10, 2008 at 4:35 PM, Stefan Seefeld
<seefeldsympatico.ca> wrote:
> Neal Becker wrote:
>
>  > Surprisingly, this still doesn't work:
>  > ...
>  >     .setattr ("TAIL_BITS",
turbo_enc_1_15::TAIL_BITS)
>  >
>  > ImportError: ../mod/turbo_enc_1_15.so: undefined
symbol: _ZN14turbo_enc_1_159TAIL_BITSE
>
>  And this:
>
>  int const tail_bits = turbo_enc_1_15::TAIL_BITS;
>
>  ...
>  .setattr("TAIL_BITS", tail_bits)
>
>  ?
>
>  Note that the class_<>::setattr() method still
takes a reference of its
>  second argument, which, if the compiler doesn't
optimize it away, emits
>  a symbol reference. So, introducing this local
'tail_bits' variable has
>  basically the same effect as defining
turbo_enc_1_15::TAIL_BITS. The
>  latter would obviously be the more proper solution to
your problem, but
>  if you don't want or can't do that, such a local
variable may be a
>  viable workaround. (Not sure how portable it is,
though.)

May be you should try some other way:

using boost::python;
scope().attr("TAIL_BITS") = object(TAIL_BITS);

-- 
Roman Yakovenko
C++ Python language binding
http://www.language-
binding.net/
_______________________________________________
C++-sig mailing list
C++-sigpython.org
http:
//mail.python.org/mailman/listinfo/c++-sig

Re: undefined symbols with def_readonly
country flaguser name
United States
2008-04-10 08:55:45
Roman Yakovenko wrote:

> On Thu, Apr 10, 2008 at 4:35 PM, Stefan Seefeld
<seefeldsympatico.ca>
> wrote:
>> Neal Becker wrote:
>>
>>  > Surprisingly, this still doesn't work:
>>  > ...
>>  >     .setattr ("TAIL_BITS",
turbo_enc_1_15::TAIL_BITS)
>>  >
>>  > ImportError: ../mod/turbo_enc_1_15.so:
undefined symbol:
>>  > _ZN14turbo_enc_1_159TAIL_BITSE
>>
>>  And this:
>>
>>  int const tail_bits = turbo_enc_1_15::TAIL_BITS;
>>
>>  ...
>>  .setattr("TAIL_BITS", tail_bits)
>>
>>  ?
>>
>>  Note that the class_<>::setattr() method
still takes a reference of its
>>  second argument, which, if the compiler doesn't
optimize it away, emits
>>  a symbol reference. So, introducing this local
'tail_bits' variable has
>>  basically the same effect as defining
turbo_enc_1_15::TAIL_BITS. The
>>  latter would obviously be the more proper solution
to your problem, but
>>  if you don't want or can't do that, such a local
variable may be a
>>  viable workaround. (Not sure how portable it is,
though.)
> 
> May be you should try some other way:
> 
> using boost::python;
> scope().attr("TAIL_BITS") =
object(TAIL_BITS);
> 

Will this make it an class variable?

_______________________________________________
C++-sig mailing list
C++-sigpython.org
http:
//mail.python.org/mailman/listinfo/c++-sig

Re: undefined symbols with def_readonly
country flaguser name
United States
2008-04-10 10:11:34
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

_______________________________________________
C++-sig mailing list
C++-sigpython.org
http:
//mail.python.org/mailman/listinfo/c++-sig

Re: undefined symbols with def_readonly
country flaguser name
United States
2008-04-11 07:22:14
Stefan Seefeld wrote:

> Neal Becker wrote:
> 
>> Surprisingly, this still doesn't work:
>> ...
>>     .setattr ("TAIL_BITS",
turbo_enc_1_15::TAIL_BITS)
>> 
>> ImportError: ../mod/turbo_enc_1_15.so: undefined
symbol:
>> _ZN14turbo_enc_1_159TAIL_BITSE
> 
> And this:
> 
> int const tail_bits = turbo_enc_1_15::TAIL_BITS;
> 
> ...
> .setattr("TAIL_BITS", tail_bits)
> 
> ?
> 
> Note that the class_<>::setattr() method still
takes a reference of its
> second argument, which, if the compiler doesn't
optimize it away, emits
> a symbol reference. So, introducing this local
'tail_bits' variable has
> basically the same effect as defining
turbo_enc_1_15::TAIL_BITS. The
> latter would obviously be the more proper solution to
your problem, but
> if you don't want or can't do that, such a local
variable may be a
> viable workaround. (Not sure how portable it is,
though.)
> 
> Regards,
> Stefan
> 

The above solution works fine, thanks.

_______________________________________________
C++-sig mailing list
C++-sigpython.org
http:
//mail.python.org/mailman/listinfo/c++-sig

[1-10] [11-13]

about | contact  Other archives ( Real Estate discussion Medical topics )