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

**URL:** <https://www.ruby-forum.com/t/question-on-how-to-derive-a-class-in-an-out-of-tree-module-based-on-a-gnuradio-class/232388>\
**Category:** GNU Radio\
**Created:** [October 7, 2014, 3:59am UTC](https://www.ruby-forum.com/t/question-on-how-to-derive-a-class-in-an-out-of-tree-module-based-on-a-gnuradio-class/232388 "2014-10-07T03:59:50Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [October 7, 2014, 3:59am UTC](https://www.ruby-forum.com/t/question-on-how-to-derive-a-class-in-an-out-of-tree-module-based-on-a-gnuradio-class/232388/1 "2014-10-07T03:59:50Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![Zhe\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/d07c76/32.png) [@Zhe\_F](https://www.ruby-forum.com/u/Zhe_F)\
**Post date:** [October 7, 2014, 9:55am UTC](https://www.ruby-forum.com/t/question-on-how-to-derive-a-class-in-an-out-of-tree-module-based-on-a-gnuradio-class/232388/2 "2014-10-07T09:55:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Zhe\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/d07c76/32.png) [@Zhe\_F](https://www.ruby-forum.com/u/Zhe_F)\
**Post date:** [October 7, 2014, 11:17am UTC](https://www.ruby-forum.com/t/question-on-how-to-derive-a-class-in-an-out-of-tree-module-based-on-a-gnuradio-class/232388/3 "2014-10-07T11:17:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Zhe\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/d07c76/32.png) [@Zhe\_F](https://www.ruby-forum.com/u/Zhe_F)\
**Post date:** [October 7, 2014, 11:28am UTC](https://www.ruby-forum.com/t/question-on-how-to-derive-a-class-in-an-out-of-tree-module-based-on-a-gnuradio-class/232388/4 "2014-10-07T11:28:59Z")

</div>

-----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](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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [Discuss-gnuradio Info Page](https://lists.gnu.org/mailman/listinfo/discuss-gnuradio)

-----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-----

---

<div class="post-metadata">

**Author:** ![Zhe\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/d07c76/32.png) [@Zhe\_F](https://www.ruby-forum.com/u/Zhe_F)\
**Post date:** [October 7, 2014, 12:40pm UTC](https://www.ruby-forum.com/t/question-on-how-to-derive-a-class-in-an-out-of-tree-module-based-on-a-gnuradio-class/232388/5 "2014-10-07T12:40:49Z")

</div>

On 07 Oct 2014, at 12:02, Bastian B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

> [https://github.com/bastibl/gr-ieee802-11/blob/master/swig/ieee802\_11\_swig.i#L18](https://github.com/bastibl/gr-ieee802-11/blob/master/swig/ieee802_11_swig.i#L18)

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

---

<div class="post-metadata">

**Author:** ![Zhe\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/d07c76/32.png) [@Zhe\_F](https://www.ruby-forum.com/u/Zhe_F)\
**Post date:** [October 7, 2014, 12:04pm UTC](https://www.ruby-forum.com/t/question-on-how-to-derive-a-class-in-an-out-of-tree-module-based-on-a-gnuradio-class/232388/6 "2014-10-07T12:04:02Z")

</div>

Hi,

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

[https://github.com/bastibl/gr-ieee802-11/blob/master/swig/ieee802\_11\_swig.i#L18](https://github.com/bastibl/gr-ieee802-11/blob/master/swig/ieee802_11_swig.i#L18)

Hope that helps,  
Bastian

On 07 Oct 2014, at 11:27, Marcus M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

> **[Home](https://www.bastibl.net/)**
>
> I'm Bastian Bloessl, a Research Group Leader at the Secure Mobile Networking Lab, TU Darmstadt. Checkout my blog, projects, publications, and resume; or connect on Github, Twitter, YouTube, or Facebook.

---

<div class="post-metadata">

**Author:** ![Zhe\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/d07c76/32.png) [@Zhe\_F](https://www.ruby-forum.com/u/Zhe_F)\
**Post date:** [October 7, 2014, 2:20pm UTC](https://www.ruby-forum.com/t/question-on-how-to-derive-a-class-in-an-out-of-tree-module-based-on-a-gnuradio-class/232388/7 "2014-10-07T14:20:08Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> >

–  
Zhe F.

Electrical Engineering: System

University of Michigan Ann Arbor

Tel: 734-834-3188

---

<div class="post-metadata">

**Author:** ![Zhe\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/d07c76/32.png) [@Zhe\_F](https://www.ruby-forum.com/u/Zhe_F)\
**Post date:** [October 12, 2014, 4:34pm UTC](https://www.ruby-forum.com/t/question-on-how-to-derive-a-class-in-an-out-of-tree-module-based-on-a-gnuradio-class/232388/8 "2014-10-12T16:34:52Z")

</div>

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.
