Question on how to derive a class in an out-of-tree module based on a gnuradio class

Dear all,

I’m trying to derive a packet_header2 class in my own OOT module based
on
gr::digital::packet_header_default. I followed the way in
packet_heade_ofdm of gr-digital and made packet_header2.h and
packet_header2.cc in my own OOT module.

But when I tried to import my_oot in python, it returned an undefined
symbol error like this:

Traceback (most recent call last):
File “”, line 1, in
File “/usr/local/lib/python2.7/dist-packages/my_oot/init.py”, line
45, in
from my_oot_swig import *
File “/usr/local/lib/python2.7/dist-packages/my_oot/my_oot_cdma.py”,
line
26, in
_my_oot_swig = swig_import_helper()
File “/usr/local/lib/python2.7/dist-packages/cdma/cdma_swig.py”, line
22,
in swig_import_helper
_mod = imp.load_module(‘_my_oot_swig’, fp, pathname, description)
ImportError: /usr/local/lib/libgnuradio-my_oot.so: undefined symbol:
_ZTIN2gr7digital21packet_header_defaultE

I searched the list and found a previous answered question below
http://gnuradio.4.n7.nabble.com/so-undefined-symbol-ZN2gr6blocks12count-bits16E-td46270.html

where Marcus suggested editing the CMakeList.txt files by adding the
module
I needed. So I added

set(GR_REQUIRED_COMPONENTS RUNTIME DIGITAL) in CMakeLists.txt.

and then. This above error disappeared when I import my_oot again in
python. But this problem isn’t solved. I tried to access some functions
of
packet_header_default like formatter and base, it returned me an
AtrributeError like this:

AttributeError: ‘packet_header2_sptr’ object has no attribute
‘formatter’,
which means the packet_header2 wasn’t really a derived class of
packet_header_default.

I confirmed my conjecture by checking the
/usr/local/lib/python2.7/dist-packages/my_oot/my_oot_swig.py where the
classes are stored in python. I found that the class packet_header2 is
defined as class packet_header2(object). So the packet_header2 isn’t
installed as a derived class of gr::digital::packet_header_default.
what
I expected was packet_header2(gr::digital::packet_header_default).

So I’m asking you that how to correctly derive my class (eg:
packet_header2) in my own oot module based on a class (eg:
packet_header_default) in an existing module (eg: gr-digital)?

My packet_header2.h and packet_header2.cc are attached for your
reference.

Thanks!
Best,
Zhe


Zhe F.

Electrical Engineering: System
University of Michigan Ann Arbor

This looks like a linker error.
In your main CMakeList.txt, you have to add DIGITAL to the line
containing

set(GR_REQUIRED_COMPONENTS …

If you already have that, sometimes make clean helps, when for some
reason linker/ccache/black magic involving CMake failed.

Greetings,
Marcus

On 10/07/2014 09:54 AM, Marcus M. wrote:

This looks like a linker error.
In your main CMakeList.txt, you have to add DIGITAL to the line containing

set(GR_REQUIRED_COMPONENTS …

The OP mentioned he’d already done that, but I still agree with your
suspicion. It’s actually more likely some SWIG/linking issue.

Are you referencing the correct header files in your SWIG file?

M

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

… I should pay closer attention; sorry!

On 07.10.2014 11:16, Martin B. wrote:

On 07.10.2014 03:58, Zhe F. wrote:

Traceback (most recent call last): File “”, line 1, in

I searched the list and found a previous answered question
below

http://gnuradio.4.n7.nabble.com/so-undefined-symbol-ZN2gr6blocks12count-bits16E-td46270.html

where Marcus suggested editing the CMakeList.txt files by adding the
module

AttributeError: ‘packet_header2_sptr’ object has no attribute

_______________________________________________ Discuss-gnuradio
mailing list [email protected]
Discuss-gnuradio Info Page

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQEcBAEBAgAGBQJUM7IEAAoJEAFxB7BbsDrLiX8H/3gPnytHZ8+TLDJb4zWSj2yR
mn8do7lA7QmuKU5sPq9xUbUyvaN+HhzJFiap1wYop/N7rVP5VESzPFoLrcci23RR
/zfjy+pMyHw4WudpjpBVB0laSwQR6+SjyiKZEl0O/wlWxoTWSGOx5Q18YfOdW/i5
xWWTn9XDU5gmNnPNZElowyIEyG6yy7rpha8lIjzdaV6V5kPdNcw8nopOx4P5gb+z
eUUAF0Z/3UCq5Og7u95hHA2F17hhh1aVy2yTYMU3JA/KpcUq/qk58K50AbS/Ycaw
miFV5hKpMne/AxIPnEIlL2EVwpirGIjgTAbk6vbMfmIz0I5QBPeZDA6fYF4Bk70=
=pGV9
-----END PGP SIGNATURE-----

On 07 Oct 2014, at 12:02, Bastian B. [email protected] wrote:

I did that in gr-ieee802-11 and IIRC I had to define GR_API in the swig config

arg, sorry! I had to #define DIGITAL_API and include
packet_header_default.h

gr-ieee802-11/swig/ieee802_11_swig.i at maint-3.8 · bastibl/gr-ieee802-11 · GitHub

I think that I also had some problems with the swig bindings without
those includes and defines.

Hi,

I did that in gr-ieee802-11 and IIRC I had to define GR_API in the swig
config

Hope that helps,
Bastian

On 07 Oct 2014, at 11:27, Marcus M. [email protected] wrote:

set(GR_REQUIRED_COMPONENTS …

followed the way in packet_heade_ofdm of gr-digital and made
line 26, in _my_oot_swig = swig_import_helper() File

and base, it returned me an AtrributeError like this:
gr::digital::packet_header_default. what I expected was


Dipl.-Inform. Bastian B.
Distributed Embedded Systems Group
University of Paderborn, Germany

Hi Marcus, Martin and Bastian,

Thanks for your help!

You are right, it’s a linker error, the reason is absolutely what Martin
mentioned that I didn’t refer the header files I used i.e
packet_header_default.h in my swig file.
I checked Bastian’s swig file and made this class working as expected!

Thanks again!
Best,
Zhe

On Tue, Oct 7, 2014 at 6:39 AM, Bastian B. [email protected]
wrote:


Zhe F.

Electrical Engineering: System

University of Michigan Ann Arbor

Tel: 734-834-3188

Zhe, every single developer who has ever written for GnuRadio runs into
this particular swig necessity and searches like mad, certain it is
done…

Congrats.