3

Ive been trying to compile a code given in the following website to create an USRP Object https://kb.ettus.com/Getting_Started_with_UHD_and_C%2B%2B

For the lazy ill just include the code:

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

I at first was utilizing GCC compiler via Code Blocks then decided to test gcc and g++ with MinGW via command lines, both at the time of compiling resulted in this:

    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

I read about linking the lib files to the project but the API i downloaded dont seem to have any .lib, .a or any other lib type files. I downloaded it from their website, http://files.ettus.com/manual/page_install.html.

Any kind of help would be tremendously appreciated, i've been trying to figure out what the issue is for hours. As a note, im working on Windows 10 OS.

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
zapper9595
  • 41
  • 3

2 Answers2

2

Those are all simply linker errors saying that, hey, you have to add the linker libraries.

I don't know what exactly you've downloaded, but the Windows installers should come with the .lib and .dlls necessary for linking under windows. otherwise, if you've dowloaded the source code, you'd have to follow the manual to build UHD on windows, and add the resulting library to your linking list.

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
  • i managed to find the .lib file for UHD and linked it by going to linker settings of my project and adding the directory to where the .lib file is but i keep getting the same errors. The file is a pspice model library i dont know if that has to do with anything – zapper9595 Feb 23 '17 at 17:40
  • hey zapper, it's extremely hard to debug something like this remotely, but if you're still getting the same linker errors, you haven't used the right library, or you're not using it in the right place. – Marcus Müller Feb 23 '17 at 17:44
  • I think the binary installation missed some files, i'll contact them and see what they have to say, thanks Marcus! – zapper9595 Feb 23 '17 at 18:36
1

Are you using the -luhd option in your command line when compiling?

If you installed uhd, most probably, you already have the library correctly added to the include path and adding that option will fix the problem.

So the g++ line should look like:

g++ my_file.cpp -o program_name -luhd
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Oznerol
  • 73
  • 6