Object file associated with UHD (USRP Hardware Dri

2019-08-21 21:51发布

问题:

I am trying to compile a C++ file that uses the utilities of UHD (USRP Hardware Driver) in MATLAB. This is in connection with trying to use a USRP called NI-2954R with MATLAB 2013b on a 64-bit system with windows 10 OS.

The following is the mex command:

mex -largeArrayDims -v -g rx_samples_to_file.cpp   -I. "C:\Users\VINAYAK KARANDIKAR\Documents\MATLAB\MATLAB\Thesis\MATLAB_USRP_INTERFACE\UHD_sample_programs_from_GitHub\uhd"...
    -I."C:\Users\VINAYAK KARANDIKAR\Documents\MATLAB\MATLAB\Thesis\MATLAB_USRP_INTERFACE\UHD_sample_programs_from_GitHub\boost_1_55_0\boost"...
    -L."C:\Program Files\MATLAB\R2013b\extern\lib\win64\microsoft"  ...
     uhd.lib  ...
     uhd.lib libmx.lib libmex.lib libmat.lib ...
    "C:\Program Files\MATLAB\R2013b\extern\lib\win64\microsoft"

And I receive the following error:

LINK : fatal error LNK1181: cannot open input file 'C:\Users\VINAYAK KARANDIKAR\Documents\MATLAB\MATLAB\Thesis\MATLAB_USRP_INTERFACE\UHD_sample_programs_from_GitHub\uhd.obj' 

  C:\PROGRA~1\MATLAB\R2013B\BIN\MEX.PL: Error: Link of 'rx_samples_to_file.mexw64' failed. 

Unable to complete successfully.

Error in make_rx_samples_to_file (line 4)
mex -largeArrayDims -v -g rx_samples_to_file.cpp   -I. "C:\Users\VINAYAK
KARANDIKAR\Documents\MATLAB\MATLAB\Thesis\MATLAB_USRP_INTERFACE\UHD_sample_programs_from_GitHub\uhd

Why do I get this error and how can I fix the compilation?

回答1:

Your MEX-command has some duplicated parts, I will assume this is because of copy-paste errors. I will assume you actually used:

mex -largeArrayDims -v -g rx_samples_to_file.cpp ...
    -I. "C:\Users\VINAYAK KARANDIKAR\Documents\MATLAB\MATLAB\Thesis\MATLAB_USRP_INTERFACE\UHD_sample_programs_from_GitHub\uhd"...
    -I."C:\Users\VINAYAK KARANDIKAR\Documents\MATLAB\MATLAB\Thesis\MATLAB_USRP_INTERFACE\UHD_sample_programs_from_GitHub\boost_1_55_0\boost"...
    -L."C:\Program Files\MATLAB\R2013b\extern\lib\win64\microsoft"  ...
     uhd.lib libmx.lib libmex.lib libmat.lib

You have an argument -I., indicating you want to add the current directory (.) to the compiler's include path, then another argument "C:\Users\VINAYAK KARANDIKAR\Documents\MATLAB\MATLAB\Thesis\MATLAB_USRP_INTERFACE\UHD_sample_programs_from_GitHub\uhd", indicating you want to add that file to the compilation. Consequently, mex will look for a file uhd.obj, which does not exist.

The solution is to not separate the two parts of the -I argument with a space, and not add a . after the -I argument (you also have this in the -L argument). This leads to:

mex -largeArrayDims -v -g rx_samples_to_file.cpp ...
    -I"C:\Users\VINAYAK KARANDIKAR\Documents\MATLAB\MATLAB\Thesis\MATLAB_USRP_INTERFACE\UHD_sample_programs_from_GitHub\uhd" ...
    -I"C:\Users\VINAYAK KARANDIKAR\Documents\MATLAB\MATLAB\Thesis\MATLAB_USRP_INTERFACE\UHD_sample_programs_from_GitHub\boost_1_55_0\boost" ...
    -L"C:\Program Files\MATLAB\R2013b\extern\lib\win64\microsoft"  ...
     uhd.lib libmx.lib libmex.lib libmat.lib

Though I'm sort of surprised that this works in MATLAB, if you look at the documentation to the mex command you'll see that the recommended syntax would be:

mex -largeArrayDims -v -g rx_samples_to_file.cpp ...
    '-IC:\Users\VINAYAK KARANDIKAR\Documents\MATLAB\MATLAB\Thesis\MATLAB_USRP_INTERFACE\UHD_sample_programs_from_GitHub\uhd' ...
    '-IC:\Users\VINAYAK KARANDIKAR\Documents\MATLAB\MATLAB\Thesis\MATLAB_USRP_INTERFACE\UHD_sample_programs_from_GitHub\boost_1_55_0\boost' ...
    '-LC:\Program Files\MATLAB\R2013b\extern\lib\win64\microsoft'  ...
     uhd.lib libmx.lib libmex.lib libmat.lib


标签: matlab mex