首页 > 解决方案 > GNURADIO UHD 库链接器问题(C++)

问题描述

我正在尝试编译以下 C++ 代码以生成 gnuradio 流程图,但我遇到了一个奇怪的链接器错误,该错误与 uhd 库有关。

 #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;
   }

我收到以下错误,我很难解决。

`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

当我删除 usrp_source 时错误消失。

以下是我的制作文件。

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

谢谢

标签: c++gnuradiouhd

解决方案


我在这里看到两个问题:

  1. API 要求您将通道数传递给make(). 见这里:https ://www.gnuradio.org/doc/doxygen-3.7.2/group__uhd__blk.html
  2. uhd::device_addr_t一张地图。如果您的 USRP 的 IP 为 192.168.10.1,则识别该设备的正确方法是addr=192.168.10.1. 见这里:https ://files.ettus.com/manual/page_identification.html

您可能还需要设置子设备规范(我在任何地方的代码中都没有看到这一点)。见这里:https ://files.ettus.com/manual/page_configuration.html


推荐阅读