# Swig and python import problem due to other out-of-tree modules used in my out-of-tree module

**URL:** <https://www.ruby-forum.com/t/swig-and-python-import-problem-due-to-other-out-of-tree-modules-used-in-my-out-of-tree-module/241326>\
**Category:** GNU Radio\
**Created:** [March 30, 2015, 6:27am UTC](https://www.ruby-forum.com/t/swig-and-python-import-problem-due-to-other-out-of-tree-modules-used-in-my-out-of-tree-module/241326 "2015-03-30T06:27:33Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [March 30, 2015, 6:27am UTC](https://www.ruby-forum.com/t/swig-and-python-import-problem-due-to-other-out-of-tree-modules-used-in-my-out-of-tree-module/241326/1 "2015-03-30T06:27:33Z")

</div>

I’ve asked this question before. But there are lots of ambiguity and  
uncertainty. Thus, this is the clarification.

I am using Reed-Solomon En/decoder in my own OOT module sources. The  
Reed-Solomon en/decoder are implemented in [gr-dvbt](https://github.com/BogdanDIA/gr-dvbt).

Important codes are:

```
[include/reed_solomon.h](

```

> <https://github.com/BogdanDIA/gr-dvbt/blob/master/include/dvbt/reed_solomon.h>

)  
[include/reed\_solomon\_enc.h](https://github.com/BogdanDIA/gr-dvbt/blob/master/include/dvbt/reed_solomon_enc.h)  
[lib/reed\_solomon.cc](https://github.com/BogdanDIA/gr-dvbt/blob/master/lib/reed_solomon.cc)  
[lib/reed\_solomon\_end\_impl.h](https://github.com/BogdanDIA/gr-dvbt/blob/master/lib/reed_solomon_enc_impl.h)  
[lib/reed\_solomon\_end\_impl.cc](https://github.com/BogdanDIA/gr-dvbt/blob/master/lib/reed_solomon_enc_impl.cc)

I’ve built and installed my module. But when I import my module in  
Python  
for tests, error occurs:

```
>>> import myOOTmodule
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File

```

“/usr/local/lib/python2.7/dist-packages/myOOTmodule/ **init**.py”, line  
51,  
in   
from myOOTmodule\_swig import \*  
File  
“/usr/local/lib/python2.7/dist-packages/myOOTmodule/myOOTmodule\_swig.py”,  
line 28, in   
\_myOOTmodule\_swig = swig\_import\_helper()  
File  
“/usr/local/lib/python2.7/dist-packages/myOOTmodule/myOOTmodule\_swig.py”,  
line 24, in swig\_import\_helper  
\_mod = imp.load\_module(‘\_myOOTmodule\_swig’, fp, pathname,  
description)  
ImportError: /usr/local/lib/libgnuradio-myOOTmodule.so: undefined  
symbol: \_ZN2gr4dvbt12reed\_solomonC1Eiiiiiiii

You can also see the error above in [gist](https://gist.github.com/gsongsong/e07883959f6a339b5d78)

The problem is that the above error occurs since I am using  
gr:dvbt::reed\_solomon, which is neither in GNU Radio source tree nor in  
my  
module.

I don’t know the exact reason for this. But in my guess…  
It seems that myOOTmodule thinks gr::dvbt::reed\_solomon is a part of  
myOOTmodule itself. But there is no declaration and implementation and  
it  
causes the error.  
Or myOOTmodule has no idea where to import gr:dvbt:reed\_solomon.

Another hypothesis is that, an OOT module cannot use other OOT modules  
(in  
swig-python?). I’m not sure about it. Or, there is a way to do this, but  
I  
just don’t know about it.

Regards,  
Jeon.

---

<div class="post-metadata">

**Author:** ![Jeon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e8c25b/32.png) [@Jeon](https://www.ruby-forum.com/u/Jeon)\
**Post date:** [March 30, 2015, 5:24pm UTC](https://www.ruby-forum.com/t/swig-and-python-import-problem-due-to-other-out-of-tree-modules-used-in-my-out-of-tree-module/241326/2 "2015-03-30T17:24:10Z")

</div>

Jeon,

I’ve recently dealt with a similar problem. Chances are that if things  
are building and installing correctly but the error is in the SWIG  
import, the actual problem lies in your CMakeLists.txt… seems like the  
C++ linker is being smart enough to get things linked correctly but SWIG  
needs you to be a bit more explicit.

Is there another project that includes Reed-Solomon that you can  
reference? See what changes they made to their CMakesLists.txt to get  
SWIG to be happy.

-Doug

* * *

From: discuss-gnuradio-bounces+danderson=removed\_email\_address@domain.invalid  
[discuss-gnuradio-bounces+danderson=removed\_email\_address@domain.invalid] on behalf  
of Jeon [removed\_email\_address@domain.invalid]  
Sent: Sunday, March 29, 2015 10:25 PM  
To: Discuss GNU Radio mailing list  
Subject: [Discuss-gnuradio] Swig and python import problem due to other  
out-of-tree modules used in my out-of-tree module

I’ve asked this question before. But there are lots of ambiguity and  
uncertainty. Thus, this is the clarification.

I am using Reed-Solomon En/decoder in my own OOT module sources. The  
Reed-Solomon en/decoder are implemented in  
[gr-dvbt](https://github.com/BogdanDIA/gr-dvbt).

Important codes are:

```
[include/reed_solomon.h](https://github.com/BogdanDIA/gr-dvbt/blob/master/include/dvbt/reed_solomon.h)
[include/reed_solomon_enc.h](https://github.com/BogdanDIA/gr-dvbt/blob/master/include/dvbt/reed_solomon_enc.h)
[lib/reed_solomon.cc](https://github.com/BogdanDIA/gr-dvbt/blob/master/lib/reed_solomon.cc)
[lib/reed_solomon_end_impl.h](https://github.com/BogdanDIA/gr-dvbt/blob/master/lib/reed_solomon_enc_impl.h)
[lib/reed_solomon_end_impl.cc](https://github.com/BogdanDIA/gr-dvbt/blob/master/lib/reed_solomon_enc_impl.cc)

```

I’ve built and installed my module. But when I import my module in  
Python for tests, error occurs:

```
>>> import myOOTmodule
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File 

```

“/usr/local/lib/python2.7/dist-packages/myOOTmodule/ **init**.py”, line  
51, in   
from myOOTmodule\_swig import \*  
File  
“/usr/local/lib/python2.7/dist-packages/myOOTmodule/myOOTmodule\_swig.py”,  
line 28, in   
\_myOOTmodule\_swig = swig\_import\_helper()  
File  
“/usr/local/lib/python2.7/dist-packages/myOOTmodule/myOOTmodule\_swig.py”,  
line 24, in swig\_import\_helper  
\_mod = imp.load\_module(‘\_myOOTmodule\_swig’, fp, pathname,  
description)  
ImportError: /usr/local/lib/libgnuradio-myOOTmodule.so: undefined  
symbol: \_ZN2gr4dvbt12reed\_solomonC1Eiiiiiiii

You can also see the error above in  
[gist](https://gist.github.com/gsongsong/e07883959f6a339b5d78)

The problem is that the above error occurs since I am using  
gr:dvbt::reed\_solomon, which is neither in GNU Radio source tree nor in  
my module.

I don’t know the exact reason for this. But in my guess…  
It seems that myOOTmodule thinks gr::dvbt::reed\_solomon is a part of  
myOOTmodule itself. But there is no declaration and implementation and  
it causes the error.  
Or myOOTmodule has no idea where to import gr:dvbt:reed\_solomon.

Another hypothesis is that, an OOT module cannot use other OOT modules  
(in swig-python?). I’m not sure about it. Or, there is a way to do this,  
but I just don’t know about it.

Regards,  
Jeon.

---

<div class="post-metadata">

**Author:** ![Jeon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e8c25b/32.png) [@Jeon](https://www.ruby-forum.com/u/Jeon)\
**Post date:** [March 30, 2015, 10:49pm UTC](https://www.ruby-forum.com/t/swig-and-python-import-problem-due-to-other-out-of-tree-modules-used-in-my-out-of-tree-module/241326/3 "2015-03-30T22:49:57Z")

</div>

Hi Jeon,

do you specify gnuradio-dvbt as one of the libraries you link against?

Greetings,  
Marcus

---

<div class="post-metadata">

**Author:** ![Jeon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e8c25b/32.png) [@Jeon](https://www.ruby-forum.com/u/Jeon)\
**Post date:** [March 31, 2015, 8:13am UTC](https://www.ruby-forum.com/t/swig-and-python-import-problem-due-to-other-out-of-tree-modules-used-in-my-out-of-tree-module/241326/4 "2015-03-31T08:13:59Z")

</div>

Dear Douglas,

Thank you for your answer.

Unfortunately, I couldn’t find other modules and projects that use  
gr-dvbt  
in their codes. Thus, I feel sort of being frustrated ☹

Or maybe I can handle it if you give me some details about CMakeLists.  
As  
you know, there are a number of CmakeLists in the project. Can it be  
done  
by modifying and fixing CMakeLists.txt under swig, python or project  
root  
directory?

As I am searching the web and archives, I’ve just found [this thread](http://lists.gnu.org/archive/html/discuss-gnuradio/2013-12/msg00223.html).  
Though I’ve not read carefully it yet and it’s been two years since that  
thread was posted, I think it might be relevant with my case.

If you have any better suggestions, I will be very thankful to it.  
Also, I will report my progress as soon as possible.

Regards,  
Jeon.

2015-03-31 0:22 GMT+09:00 Anderson, Douglas J.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![Jeon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e8c25b/32.png) [@Jeon](https://www.ruby-forum.com/u/Jeon)\
**Post date:** [March 31, 2015, 11:34am UTC](https://www.ruby-forum.com/t/swig-and-python-import-problem-due-to-other-out-of-tree-modules-used-in-my-out-of-tree-module/241326/5 "2015-03-31T11:34:12Z")

</div>

Hi Jeon,

typically, you’d call a FindSomething function in the root CMakeList

find\_library(GR\_DVBT\_LIBRARY  
NAMES  
gnuradio-dvbt  
PATHS  
/usr/lib  
/usr/local/lib  
/opt/local/lib  
/sw/lib  
)  
or so. I guess “gnuradio-dvbt.so” should be the name of the installed  
gr-dvbt library – please verify that this is correct.

Then add the resulting library name to the target\_link\_libraries  
directive in lib/CMakeList.txt:

target\_link\_libraries(\<project\_name\> ${Boost\_LIBRARIES}  
${GNURADIO\_ALL\_LIBRARIES} ${GR\_DVBT\_LIBRARY})  
and  
target\_link\_libraries(test-\<project\_name\> ${Boost\_LIBRARIES}  
${GNURADIO\_ALL\_LIBRARIES} ${GR\_DVBT\_LIBRARY} \<project\_name\>)

How is CMake able to find the headers you need to compile your module?  
If you have written functionality to detect these headers, you can  
probably do the same for the compiled gr-dvbt libraries.

Greetings,  
Marcus

---

<div class="post-metadata">

**Author:** ![Jeon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e8c25b/32.png) [@Jeon](https://www.ruby-forum.com/u/Jeon)\
**Post date:** [March 31, 2015, 4:39pm UTC](https://www.ruby-forum.com/t/swig-and-python-import-problem-due-to-other-out-of-tree-modules-used-in-my-out-of-tree-module/241326/6 "2015-03-31T16:39:25Z")

</div>

Dear, Marcus.

Thanks, it’s very helpful. But, stil somethings unresolved.

What I’ve done is:

In CMakeLists.txt of root:

```
find_package(DVBT)
if (NOT DVBT_FOUND) /* ommited */ endif()
include_directories(
    /* omitted */
    ${DVBT_INCLUDE_DIR}
)

```

Add cmake/Modules/[FindDVBT.cmake](https://gist.github.com/gsongsong/49ec2cf84d7907c7ceb0). It’s quite  
long.  
And I found that shared object (so) is libgnuradio-dvbt.so.

In lib/CMakeLists.txt:

```
target_link_libraries(gnuradio-mymodule ${DVBT_LIBRARIES})

```

A result of build and installation is:

```
pkg_check_modules(PC_DVBT gnuradio-dvbt): returns package

```

‘gnuradio-dvbt’ not found

Although I’ve changed gnuradio-dvbt to gr-dvbt, dvbt gnuradio\_dvbt,  
gr\_dvbt, libgnuradio-dvbt and other possible combinations, nothings  
different.

But DVBT\_LIBRARY returns /usr/local/lib/libgnuradio-dvbt.so and  
DVBT\_INCLUDE\_DIR returns /usr/local/include.  
I think this part is correct.

And in python:

```
>>> import mymodule
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File

```

“/usr/local/lib/python2.7/dist-packages/myOOTmodule/ **init**.py”, line  
51,  
in   
from myOOTmodule\_swig import \*  
File  
“/usr/local/lib/python2.7/dist-packages/myOOTmodule/myOOTmodule\_swig.py”,  
line 28, in   
\_myOOTmodule\_swig = swig\_import\_helper()  
File  
“/usr/local/lib/python2.7/dist-packages/myOOTmodule/myOOTmodule\_swig.py”,  
line 24, in swig\_import\_helper  
\_mod = imp.load\_module(‘\_myOOTmodule\_swig’, fp, pathname,  
description)  
ImportError: /usr/local/lib/libgnuradio-myOOTmodule.so: undefined  
symbol: \_ZN2gr4dvbt12reed\_solomonC1Eiiiiiiii

It is the same as the previous.

…

After some googling and searching, I found that gr-dvbt is not present  
in  
‘pkg-config --list-all’.  
I think it would be a bit relevant to this problem.  
If it is the case, I’d better think to use IT++ Reed Solomon.

I’ll let you know if I have further progress.

Regards,  
Jeon.

2015-03-31 18:32 GMT+09:00 Marcus Müller [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![Jeon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e8c25b/32.png) [@Jeon](https://www.ruby-forum.com/u/Jeon)\
**Post date:** [April 1, 2015, 8:31am UTC](https://www.ruby-forum.com/t/swig-and-python-import-problem-due-to-other-out-of-tree-modules-used-in-my-out-of-tree-module/241326/7 "2015-04-01T08:31:10Z")

</div>

Dear, Marcus.

Struggling for this, but still the problem is not solved.

AND ONE THING I’VE FOUND IS:

```
>>> import dvbt
>>> dir(dvbt)

```

There are no reed\_solomon, reed\_solomon\_make, reed\_solomon\_sptr,  
reed\_solomon\_sptr\_swigregister and reed\_solomon\_swigregister. But, there  
are reed\_solomon\_end\_XX and reed\_solomon\_dec\_XX. (XX is \_make, _sptr  
things)  
Do you think this has something to do with my probelm? I think there is  
no  
reed\_solomon_(…) module, thus I can’t use gr:dvbt::reed\_solomon in  
MYMODULE.  
Can it be solved if I modify gr-dvbt to have \_make, \_sptr, \_swigregister  
things? But, I wonder if it is a good way to modify other’s sources. On  
the  
contrary, it might be good if I can contribute to the gr-dvbt sources.

Or is it irrelevant with my problem?  
Anyway, I’ll try what I am thinking til some respones recevied.

Regards,  
Jeon.

2015-03-31 23:50 GMT+09:00 Marcus Müller [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![Jeon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e8c25b/32.png) [@Jeon](https://www.ruby-forum.com/u/Jeon)\
**Post date:** [March 31, 2015, 4:52pm UTC](https://www.ruby-forum.com/t/swig-and-python-import-problem-due-to-other-out-of-tree-modules-used-in-my-out-of-tree-module/241326/8 "2015-03-31T16:52:42Z")

</div>

Hi Jeon,

This looks very proper, but since gr-dvbt doesn’t supply a pkgconfig  
(.pc) file, you can’t use pkg\_check\_modules; the raw find\_library call  
you use should work, though.

also, you set DVBT\_LIBRARY, so you’ll have to use  
target\_link\_libraries(gnuradio-mymodule ${DVBT\_LIBRARY})  
(notice the singular LIBRARY).

Greetings,  
Marcus
