Search code examples
pythonc++gnuradio

gnuradio `ImportError undefined symbol`


I'm new to GNU Radio and python. I'm trying to write a correlation block, somewhere in my code I use fft filter:

gr::filter::kernel::fft_filter_ccc  *d_filter;
d_filter = new gr::filter::kernel::fft_filter_ccc(1, x_vector);
d_filter->filter(noutput_items,in_y,out);

I run

cmake ../
make 

and it complies perfectly fine, but when i try

make test

I'll get this error:

 Traceback (most recent call last):
2:   File "/home/mohammad/projects/FD/implementation_tests/oot_modules/gr-full_duplex/python/qa_fd_correlation_cc.py", line 25, in <module>
2:     import full_duplex_swig as full_duplex
2:   File "/home/mohammad/projects/FD/implementation_tests/oot_modules/gr-full_duplex/build/swig/full_duplex_swig.py", line 28, in <module>
2:     _full_duplex_swig = swig_import_helper()
2:   File "/home/mohammad/projects/FD/implementation_tests/oot_modules/gr-full_duplex/build/swig/full_duplex_swig.py", line 24, in swig_import_helper
2:     _mod = imp.load_module('_full_duplex_swig', fp, pathname, description)
2: ImportError: /home/mohammad/projects/FD/implementation_tests/oot_modules/gr-full_duplex/build/lib/libgnuradio-full_duplex.so: undefined symbol: _ZN2gr6filter6kernel14fft_filter_cccC1EiRKSt6vectorISt7complexIfESaIS5_EEi
1/1 Test #2: qa_fd_correlation_cc .............***Failed    1.30 sec

Solution

  • This often happens when you have declared a method at the header file, but you do not implement it. For example a destructor or something else.

    To find out which method it is you should demangle the undefined symbol _ZN2gr6filter6kernel14fft_filter_cccC1EiRKSt6vectorISt7complexIfESaIS5_EEi.

    This can be done using the c++filt tool. For example,

    c++filt \ _ZN2gr6filter6kernel14fft_filter_cccC1EiRKSt6vectorISt7complexIfESaIS5_EEi

    In your case this symbol is an existing symbol of the GNU Radio, located in the gr-filter module. Each GNU Radio module creates a library, so in order to resolve the undefined symbol issue you have to link against the required library. To accomplish this you have to do the following steps:

    At the CMakeLists.txt file of your module, specify on which components of GNU Radio you depend. In your case the FILTER component.

    set(GR_REQUIRED_COMPONENTS RUNTIME FILTER)
    find_package(Gnuradio "3.7.0" REQUIRED)
    

    Further dependencies can be inserted, eg:

    set(GR_REQUIRED_COMPONENTS RUNTIME FILTER DIGITAL)
    

    After that you can use the ${GNURADIO_ALL_INCLUDE_DIRS} and ${GNURADIO_ALL_LIBRARIES} auto generated variables to properly include the proper header files and link against the appropriate libraries. E.g:

    include_directories(
        ${CMAKE_SOURCE_DIR}/lib
        ${CMAKE_SOURCE_DIR}/include
        ${CMAKE_BINARY_DIR}/lib
        ${CMAKE_BINARY_DIR}/include
        ${Boost_INCLUDE_DIRS}
        ${CPPUNIT_INCLUDE_DIRS}
        ${GNURADIO_RUNTIME_INCLUDE_DIRS}
        ${GNURADIO_ALL_INCLUDE_DIRS}
    )
    
    target_link_libraries(gnuradio-howto
                          ${Boost_LIBRARIES}
                          ${GNURADIO_RUNTIME_LIBRARIES}
                          ${GNURADIO_ALL_LIBRARIES})
    

    For more info refer here.