【问题标题】:Undefined Reference[USRP] [UHD]未定义参考[USRP] [UHD]
【发布时间】:2017-07-13 12:59:32
【问题描述】:

我一直在尝试编译以下网站中给出的代码来创建一个 USRP 对象 https://kb.ettus.com/Getting_Started_with_UHD_and_C%2B%2B

对于懒惰的病人,只需包含代码:

#include <uhd/utils/thread_priority.hpp>
#include <uhd/utils/safe_main.hpp>
#include <uhd/usrp/multi_usrp.hpp>
#include <uhd/exception.hpp>
#include <uhd/types/tune_request.hpp>
#include <boost/program_options.hpp>
#include <boost/format.hpp>
#include <boost/thread.hpp>
#include <iostream>

int UHD_SAFE_MAIN(int argc, char *argv[]) {
    uhd::set_thread_priority_safe();

    std::string device_args("addr=192.168.10.2");
    std::string subdev("A:0");
    std::string ant("TX/RX");
    std::string ref("internal");

    double rate(1e6);
    double freq(915e6);
    double gain(10);
    double bw(1e6);

    //create a usrp device
    std::cout << std::endl;
    std::cout << boost::format("Creating the usrp device with: %s...") % device_args << std::endl;
    uhd::usrp::multi_usrp::sptr usrp = uhd::usrp::multi_usrp::make(device_args);

    // Lock mboard clocks
    std::cout << boost::format("Lock mboard clocks: %f") % ref << std::endl;
    usrp->set_clock_source(ref);

    //always select the subdevice first, the channel mapping affects the other settings
    std::cout << boost::format("subdev set to: %f") % subdev << std::endl;
    usrp->set_rx_subdev_spec(subdev);
    std::cout << boost::format("Using Device: %s") % usrp->get_pp_string() << std::endl;

    //set the sample rate
    if (rate <= 0.0) {
        std::cerr << "Please specify a valid sample rate" << std::endl;
        return ~0;
    }

    // set sample rate
    std::cout << boost::format("Setting RX Rate: %f Msps...") % (rate / 1e6) << std::endl;
    usrp->set_rx_rate(rate);
    std::cout << boost::format("Actual RX Rate: %f Msps...") % (usrp->get_rx_rate() / 1e6) << std::endl << std::endl;

    // set freq
    std::cout << boost::format("Setting RX Freq: %f MHz...") % (freq / 1e6) << std::endl;
    uhd::tune_request_t tune_request(freq);
    usrp->set_rx_freq(tune_request);
    std::cout << boost::format("Actual RX Freq: %f MHz...") % (usrp->get_rx_freq() / 1e6) << std::endl << std::endl;

    // set the rf gain
    std::cout << boost::format("Setting RX Gain: %f dB...") % gain << std::endl;
    usrp->set_rx_gain(gain);
    std::cout << boost::format("Actual RX Gain: %f dB...") % usrp->get_rx_gain() << std::endl << std::endl;

    // set the IF filter bandwidth
    std::cout << boost::format("Setting RX Bandwidth: %f MHz...") % (bw / 1e6) << std::endl;
    usrp->set_rx_bandwidth(bw);
    std::cout << boost::format("Actual RX Bandwidth: %f MHz...") % (usrp->get_rx_bandwidth() / 1e6) << std::endl << std::endl;

    // set the antenna
    std::cout << boost::format("Setting RX Antenna: %s") % ant << std::endl;
    usrp->set_rx_antenna(ant);
    std::cout << boost::format("Actual RX Antenna: %s") % usrp->get_rx_antenna() << std::endl << std::endl;

    return EXIT_SUCCESS;
}

我一开始是通过代码块使用 GCC 编译器,然后决定用 MinGW 测试 gcc 和 g++ 通过命令行,在编译时都导致:

    main.cpp:17: undefined reference to `_imp___ZN3uhd24set_thread_priority_safeEfb'
   main.cpp:32: undefined reference to `_imp___ZN3uhd13device_addr_tC1ERKSs'
    main.cpp:32: undefined reference to `_imp___ZN3uhd4usrp10multi_usrp4makeERKNS_13device_addr_tE'
    main.cpp:40: undefined reference to `_imp___ZN3uhd4usrp13subdev_spec_tC1ERKSs'
    main.cpp:56: undefined reference to `_imp___ZN3uhd14tune_request_tC1Ed'
    obj\Debug\main.o: In function `ZN3uhd4usrp10multi_usrp11set_rx_gainEdj':
    multi_usrp.hpp:595: undefined reference to `_imp___ZN3uhd4usrp10multi_usrp9ALL_GAINSE'
    obj\Debug\main.o: In function `ZN3uhd4usrp10multi_usrp11get_rx_gainEj':
    multi_usrp.hpp:637: undefined reference to `_imp___ZN3uhd4usrp10multi_usrp9ALL_GAINSE'
    collect2.exe: error: ld returned 1 exit status

我阅读了有关将 lib 文件链接到项目的信息,但我下载的 API 似乎没有任何 .lib、.a 或任何其他 lib 类型的文件。我是从他们的网站上下载的,http://files.ettus.com/manual/page_install.html

任何形式的帮助都将不胜感激,我几个小时以来一直试图找出问题所在。请注意,我正在使用 Windows 10 操作系统。

【问题讨论】:

    标签: c++ gcc linker usrp uhd


    【解决方案1】:

    这些都是简单的链接器错误,说,嘿,你必须添加链接器库。

    我不知道您究竟下载了什么,但 Windows 安装程序应该附带在 Windows 下进行链接所需的 .lib 和 .dll。否则,如果您已下载源代码,则必须按照手册在 Windows 上构建 UHD,并将生成的库添加到链接列表中。

    【讨论】:

    • 我设法找到了 UHD 的 .lib 文件,并通过转到我的项目的链接器设置并将目录添加到 .lib 文件所在的位置来链接它,但我不断收到相同的错误。该文件是一个 pspice 模型库,我不知道这是否与任何事情有关
    • 嘿 zapper,远程调试这样的东西非常困难,但是如果您仍然遇到相同的链接器错误,则说明您没有使用正确的库,或者您没有使用它正确的地方。
    • 我认为二进制安装丢失了一些文件,我会联系他们,看看他们有什么要说的,谢谢 Marcus!
    【解决方案2】:

    您在编译时是否在命令行中使用-luhd 选项?

    如果您安装了 uhd,很可能您已经将库正确添加到包含路径中,添加该选项将解决问题。

    所以g++ 行应该是这样的:

    g++ my_file.cpp -o program_name -luhd
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-16
      • 2015-01-14
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多