# Hierarchical Block in c++ not working, linker or swig problem

**URL:** <https://www.ruby-forum.com/t/hierarchical-block-in-c-not-working-linker-or-swig-problem/232798>\
**Category:** GNU Radio\
**Created:** [October 28, 2014, 7:53pm UTC](https://www.ruby-forum.com/t/hierarchical-block-in-c-not-working-linker-or-swig-problem/232798 "2014-10-28T19:53:15Z")\
**Posts on this page:** 2\
**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 28, 2014, 7:53pm UTC](https://www.ruby-forum.com/t/hierarchical-block-in-c-not-working-linker-or-swig-problem/232798/1 "2014-10-28T19:53:15Z")

</div>

Hi list.

I am trying to write a hierarchical block in c++ in an OOT module.  
I create the block with the gr\_modtool and try to make a very simple  
hier block. The only relevant changes to the template are:

in the …impl.cc:

#include \<gnuradio/blocks/copy.h\>  
…  
testhier::make()… unchanged  
…  
gr::blocks::copy::sptr copy(gr::blocks::copy::make(sizeof(gr\_complex)));  
connect(self(), 0, copy, 0);  
connect(copy, 0, self(), 0);

testhier\_impl::testhier\_impl()  
: gr::hier\_block2(“testhier”,  
gr::io\_signature::make(1, 1, sizeof(gr\_complex)),  
gr::io\_signature::make(1, 1, sizeof(gr\_complex)))  
{  
gr::blocks::copy::sptr  
copy(gr::blocks::copy::make(sizeof(gr\_complex)));  
connect(self(), 0, copy, 0);  
connect(copy, 0, self(), 0);  
}

So this should be the quite simplest form of a hier block. However, the  
following wierdnesses occur:

On Ubuntu:  
make is successful  
If I import the module in python, I get a segmentation fault. As far as  
I got with gdb, the error may be somewhere in swig.  
However, if I first do “from gnuradio import blocks”, the import is  
successful, but the module only contains the python blocks, all c++  
blocks are missing.  
When I only use a block from the same OOT module in the hier block, the  
import also is successful, but again the c++ blocks are missing.

On arch linux:  
make fails with a linker error:  
undefined reference to `gr::blocks::copy::make(unsigned long)’  
However if I only use a block from the same OOT module in the hier  
block, the whole thing seems to work.

What am I doing wrong? Did I forget to include something? Can it be that  
hard to make a c++ hier block?

Thanks for your help

Julius

---

<div class="post-metadata">

**Author:** ![Julius\_Durst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f14d63/32.png) [@Julius\_Durst](https://www.ruby-forum.com/u/Julius_Durst)\
**Post date:** [November 5, 2014, 4:46pm UTC](https://www.ruby-forum.com/t/hierarchical-block-in-c-not-working-linker-or-swig-problem/232798/2 "2014-11-05T16:46:10Z")

</div>

Hi,

I forgot to edit the CMakeList.txt to add the GR components that I used  
(the line set(GR\_REQUIRED\_COMPONENTS… ).

I still find it strange, that on one PC I got a linker error (which  
obviously was the Issue and led me to the solution) and the other one  
builds without complaint but okay.

Regards  
Julius
