0

I am trying to compile the following C++ code to generate a gnuradio flow graph but I am running into a weird linker error that has something to the uhd library.

 #include <gnuradio/top_block.h>
 #include <gnuradio/filter/firdes.h>
 #include <gnuradio/filter/freq_xlating_fir_filter_ccf.h>
 #include <gnuradio/analog/quadrature_demod_cf.h>
 #include <gnuradio/blocks/vector_sink_b.h>
 #include <gnuradio/uhd/usrp_source.h>
 #include <gnuradio/digital/clock_recovery_mm_cc.h>
 #include <gnuradio/digital/binary_slicer_fb.h>
 #include <gnuradio/analog/pwr_squelch_cc.h>
 #include <gnuradio/blocks/unpacked_to_packed_bb.h>
 #include <gnuradio/analog/pwr_squelch_cc.h>

 using namespace std;

 Linker error with the UHD library.


 int main(){

    double transition_width = 300e3;
    double sample_rate  = 4e6;
    double data_rate = 1e6;
    double cutoff_freq = 2e6;
    double ble_channel_spacing = 2e6;
    int ble_channel = ble_channel = 38;
    double ble_base_freq = 2402e6;
    double squelch_threshold = -110;
    double sensivity = 1.0;
    double rf_gain = rf_gain = 74;
    std::vector<float> taps = gr::filter::firdes::low_pass(1.0,  sample_rate, cutoff_freq, transition_width, gr::filter::firdes::WIN_HAMMING, 6.76);
    int gfsk_sps = (int)(sample_rate / data_rate);
    float gfsk_omega_limit = 0.035;
    float gfsk_mu = 0.5;
    float gfsk_gain_mu = 0.8;
    float freq_offset = 0.0;
    double freq = ble_base_freq+(ble_channel_spacing * ble_channel);
    float freq_error = 0.0;

    ///more parameters
    float omega = gfsk_sps*(1.0+freq_error);
    float gain_omega = .25 * gfsk_gain_mu * gfsk_gain_mu;


    gr::top_block_sptr tb = gr::make_top_block("dial_tone");
    //setting up the USRP block
    string device_addr = "192.168.10.1";
    gr::uhd::usrp_source::sptr source = gr::uhd::usrp_source::make(device_addr, uhd::stream_args_t("fc32"));;
    source->set_samp_rate(sample_rate);
    source->set_center_freq(freq);
    source->set_gain(rf_gain);
    source->set_antenna("RX2",0);


    //setting up the filter 
    gr::filter::freq_xlating_fir_filter_ccf::sptr filter_ccc = gr::filter::freq_xlating_fir_filter_ccf::make(1,taps,0.0,sample_rate);

    //demodulator setup
    gr::analog::quadrature_demod_cf::sptr qi_demod = gr::analog::quadrature_demod_cf::make(1.0/sensivity);

    //the clock recovery module 
    gr::digital::clock_recovery_mm_cc::sptr clock_rec = gr::digital::clock_recovery_mm_cc::make(omega,gain_omega,gfsk_mu,gfsk_gain_mu, gfsk_omega_limit);


    //setting the slicer
    gr::digital::binary_slicer_fb::sptr slicer = gr::digital::binary_slicer_fb::make();

    //unpacking 
    gr::blocks::unpacked_to_packed_bb::sptr unpack = gr::blocks::unpacked_to_packed_bb::make(1,gr::GR_LSB_FIRST);


    //power squelch
    gr::analog::pwr_squelch_cc::sptr squelch = gr::analog::pwr_squelch_cc::make(squelch_threshold);


    //vector sink 
    gr::blocks::vector_sink_b::sptr vect_sink = gr::blocks::vector_sink_b::make();

    ///make the connections
    tb->connect(source,0,squelch,0);
    tb->connect(squelch,0,filter_ccc,0);
    tb->connect(filter_ccc,0,qi_demod,0);
    tb->connect(qi_demod,0,clock_rec,0);
    tb->connect(clock_rec,0,slicer,0);
    tb->connect(slicer,0,unpack,0);
    tb->connect(unpack,0,vect_sink,0);





    tb->start();
    cout<<"gnuradio thread is running"<<endl;
    tb->stop();
    tb->wait();
    return 0;
   }

I am getting the following error which I am having hard time resolving.

`Undefined symbols for architecture x86_64:
  "uhd::device_addr_t::device_addr_t(std::__1::basic_string<char,     std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      _main in gr_ble.cpp.o
      uhd::stream_args_t::stream_args_t(std::__1::basic_string<char,   std::__1::char_traits<char>, std::__1::allocator<char> > const&,  std::__1::basic_string<char, std::__1::char_traits<char>,  std::__1::allocator<char> > const&) in gr_ble.cpp.o
 ld: symbol(s) not found for architecture x86_64
 clang: error: linker command failed with exit code 1 (use -v to see  invocation)
 make[2]: *** [gr_ble] Error 1
 make[1]: *** [CMakeFiles/gr_ble.dir/all] Error 2
 make: *** [all] Error 2

The error disappears when I remove the usrp_source.

The following is my make file.

cmake_minimum_required(VERSION 2.6)
 project(gr_ble CXX)

 find_package(Boost "1.35" COMPONENTS system)
 set(GR_REQUIRED_COMPONENTS RUNTIME ANALOG AUDIO BLOCKS FILTER DIGITAL UHD)
 find_package(Gnuradio "3.7.2" REQUIRED)

 include_directories(${GNURADIO_ALL_INCLUDE_DIRS})


 add_executable(gr_ble gr_ble.cpp)
 target_link_libraries(gr_ble ${Boost_LIBRARIES} ${GNURADIO_ALL_LIBRARIES})

Thanks

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219

1 Answers1

0

I see two issues here:

  1. The API calls for you to pass in the number of channels to make(). See here: https://www.gnuradio.org/doc/doxygen-3.7.2/group__uhd__blk.html
  2. The uhd::device_addr_t is a map. If your USRP has an IP of 192.168.10.1, the correct way to identify that device is addr=192.168.10.1. See here: https://files.ettus.com/manual/page_identification.html

You will probably need to set the sub-device specification as well (I don't see this in your code anywhere). See here: https://files.ettus.com/manual/page_configuration.html

It'sPete
  • 5,083
  • 8
  • 39
  • 72
  • Hi Pete, Thanks for the feedback. Their example here(https://github.com/gnuradio/gnuradio/tree/master/gr-uhd/examples/c%2B%2B) seems to be doing the same thing so I am not sure why that would be a problem. But the behavior didn't change after trying your suggestions anyway. – Ina Sarhaye Aug 14 '18 at 19:33
  • Looks like your CMake might be missing some libraries as well. Take a look here: https://github.com/gnuradio/gnuradio/blob/master/gr-uhd/examples/c%2B%2B/CMakeLists.txt – It'sPete Aug 14 '18 at 20:15
  • Some of those libraries I am not using but the problem persists when I include them anyway. Thanks @Pete! – Ina Sarhaye Aug 17 '18 at 19:37