Mex file error with UHD
    8 views (last 30 days)
  
       Show older comments
    
    Anabel almodovar
 on 19 Jul 2018
  
    
    
    
    
    Commented: VINAYAK KARANDIKAR
 on 30 Mar 2019
            I am working with a USRP x310 and a TwinRx daughterboard, Ubuntu 16.04 LTS and Matlab 2018a. I am trying to build a Mex fiel to connect with the x310 from Matlab. Initially I thought about using the communication USRP toolbox but I can't use it with a TwinRx.
I have problems when I compile the C++ file because it doesn't take the paths correctly and Matlab doesn't recognize UHD functions.
mex -v -R2018a '-L/usr/lib/x86_64-linux-gnu' -lboost_system -I/usr/include -I/usr/include/boost -I/usr/include/boost/algorithm  -I/usr/include/boost/thread -I/home/rs3lab/workarea-uhd/uhd/host/include/uhd -I/home/rs3lab/workarea-uhd/uhd/host/include/uhd/types -I/home/rs3lab/workarea-uhd/uhd/host/include/uhd/utils -I/home/rs3lab/workarea-uhd/uhd/host/include/uhd/usrp  IdeparMexV2.cpp
Verbose mode is on.
... Looking for compiler 'g++' ...
... Executing command 'which g++' ...Yes ('/usr/bin/g++').
... Executing command 'g++ -print-file-name=libstdc++.so' ...Yes ('/usr/lib/gcc/x86_64-linux-gnu/5/libstdc++.so').
... Executing command 'g++ -dumpversion' ...Yes ('5.5.0').
... Executing command 'which g++' ...Yes ('/usr/bin/g++').
... Looking for folder '/usr' ...Yes.
... Executing command 'g++ -dumpmachine' ...Yes ('x86_64-linux-gnu').
Found installed compiler 'g++'.
Set INCLUDE = /usr/lib/gcc/x86_64-linux-gnu/5.5.0/include;/usr/include/c++/5.5.0;/usr/include/c++/5.5.0/x86_64-linux-gnu;/usr/include/c++/5.5.0/backward;/usr/lib/gcc/x86_64-linux-gnu/5.5.0/include;/usr/include/c++/5.5.0;/usr/include/c++/5.5.0/x86_64-linux-gnu;/usr/include/c++/5.5.0/backward;
Options file details
-------------------------------------------------------------------
  Compiler location: /usr/bin/g++
  Options file: /home/rs3lab/.matlab/R2018a/mex_C++_glnxa64.xml
  CMDLINE2 : /usr/bin/g++ -pthread -Wl,--no-undefined  -shared -O -Wl,--version-script,"/usr/local/MATLAB/R2018a/extern/lib/glnxa64/c_exportsmexfileversion.map" /tmp/mex_420292310722548_10505/IdeparMexV2.o /tmp/mex_420292310722548_10505/cpp_mexapi_version.o   -lboost_system   -L/usr/lib/x86_64-linux-gnu   -Wl,--as-needed -Wl,-rpath-link,/usr/local/MATLAB/R2018a/bin/glnxa64 -L"/usr/local/MATLAB/R2018a/bin/glnxa64" -Wl,-rpath-link,/usr/local/MATLAB/R2018a/extern/bin/glnxa64 -L"/usr/local/MATLAB/R2018a/extern/bin/glnxa64" -lMatlabDataArray -lmx -lmex -lmat -lm -lstdc++ -o IdeparMexV2.mexa64
  CXX : /usr/bin/g++
  DEFINES : -DMX_COMPAT_64  -DMATLAB_MEXCMD_RELEASE=R2018a  -DUSE_MEX_CMD   -D_GNU_SOURCE -DMATLAB_MEX_FILE 
  MATLABMEX : -DMATLAB_MEX_FILE 
  CFLAGS : -fexceptions -fPIC -fno-omit-frame-pointer -pthread
  CXXFLAGS : -fexceptions -fPIC -fno-omit-frame-pointer -pthread -std=c++11
  INCLUDE : -I"/usr/include" -I"/usr/include/boost" -I"/usr/include/boost/algorithm" -I"/usr/include/boost/thread" -I"/home/rs3lab/workarea-uhd/uhd/host/include/uhd" -I"/home/rs3lab/workarea-uhd/uhd/host/include/uhd/types" -I"/home/rs3lab/workarea-uhd/uhd/host/include/uhd/utils" -I"/home/rs3lab/workarea-uhd/uhd/host/include/uhd/usrp"  -I"/usr/local/MATLAB/R2018a/extern/include" -I"/usr/local/MATLAB/R2018a/simulink/include"
  CXXOPTIMFLAGS : -O -DNDEBUG
  CXXDEBUGFLAGS : -g
  LDXX : /usr/bin/g++
  LDFLAGS : -pthread -Wl,--no-undefined 
  LDTYPE : -shared
  LINKEXPORT : -Wl,--version-script,"/usr/local/MATLAB/R2018a/extern/lib/glnxa64/mexFunction.map"
  LINKEXPORTVER : -Wl,--version-script,"/usr/local/MATLAB/R2018a/extern/lib/glnxa64/c_exportsmexfileversion.map"
  LINKLIBS : -lboost_system   -L/usr/lib/x86_64-linux-gnu   -Wl,--as-needed -Wl,-rpath-link,/usr/local/MATLAB/R2018a/bin/glnxa64 -L"/usr/local/MATLAB/R2018a/bin/glnxa64" -Wl,-rpath-link,/usr/local/MATLAB/R2018a/extern/bin/glnxa64 -L"/usr/local/MATLAB/R2018a/extern/bin/glnxa64" -lMatlabDataArray -lmx -lmex -lmat -lm -lstdc++
  LDOPTIMFLAGS : -O
  LDDEBUGFLAGS : -g
  MWCPPLIB : "/usr/local/MATLAB/R2018a/sys/os/glnxa64/libstdc++.so.6"
  OBJEXT : .o
  LDEXT : .mexa64
  SETENV : CC="gcc"
                CXX="/usr/bin/g++"
                CFLAGS="-fexceptions -fPIC -fno-omit-frame-pointer -pthread -DMX_COMPAT_64  -DMATLAB_MEXCMD_RELEASE=R2018a  -DUSE_MEX_CMD   -D_GNU_SOURCE -DMATLAB_MEX_FILE "
                CXXFLAGS="-fexceptions -fPIC -fno-omit-frame-pointer -pthread -std=c++11 -DMX_COMPAT_64  -DMATLAB_MEXCMD_RELEASE=R2018a  -DUSE_MEX_CMD   -D_GNU_SOURCE -DMATLAB_MEX_FILE "
                COPTIMFLAGS="-O -DNDEBUG"
                CXXOPTIMFLAGS="-O -DNDEBUG"
                CDEBUGFLAGS="-g"
                CXXDEBUGFLAGS="-g"
                LD="gcc"
                LDXX="/usr/bin/g++"
                LDFLAGS="-pthread -Wl,--no-undefined  -shared -lboost_system   -L/usr/lib/x86_64-linux-gnu   -Wl,--as-needed -Wl,-rpath-link,/usr/local/MATLAB/R2018a/bin/glnxa64 -L"/usr/local/MATLAB/R2018a/bin/glnxa64" -Wl,-rpath-link,/usr/local/MATLAB/R2018a/extern/bin/glnxa64 -L"/usr/local/MATLAB/R2018a/extern/bin/glnxa64" -lMatlabDataArray -lmx -lmex -lmat -lm -lstdc++ -Wl,--version-script,"/usr/local/MATLAB/R2018a/extern/lib/glnxa64/mexFunction.map""
                LDDEBUGFLAGS="-g"
  GCC : /usr/bin/g++
  CPPLIB_DIR : /usr/lib/gcc/x86_64-linux-gnu/5/libstdc++.so
  VER : 5.5.0
  GCCDIR : /usr
  GCC_TARGET : x86_64-linux-gnu
  MATLABROOT : /usr/local/MATLAB/R2018a
  ARCH : glnxa64
  SRC : "/home/rs3lab/Escritorio/codigos_idepar_C_funcionando/IdeparMexV2.cpp";"/usr/local/MATLAB/R2018a/extern/version/cpp_mexapi_version.cpp"
  OBJ : /tmp/mex_420292310722548_10505/IdeparMexV2.o;/tmp/mex_420292310722548_10505/cpp_mexapi_version.o
  OBJS : /tmp/mex_420292310722548_10505/IdeparMexV2.o /tmp/mex_420292310722548_10505/cpp_mexapi_version.o 
  SRCROOT : /home/rs3lab/Escritorio/codigos_idepar_C_funcionando/IdeparMexV2
  DEF : /tmp/mex_420292310722548_10505/IdeparMexV2.def
  EXP : "IdeparMexV2.exp"
  LIB : "IdeparMexV2.lib"
  EXE : IdeparMexV2.mexa64
  ILK : "IdeparMexV2.ilk"
  MANIFEST : "IdeparMexV2.mexa64.manifest"
  TEMPNAME : IdeparMexV2
  EXEDIR : 
  EXENAME : IdeparMexV2
  OPTIM : -O -DNDEBUG
  LINKOPTIM : -O
  CMDLINE1_0 : /usr/bin/g++ -c -DMX_COMPAT_64  -DMATLAB_MEXCMD_RELEASE=R2018a  -DUSE_MEX_CMD   -D_GNU_SOURCE -DMATLAB_MEX_FILE  -I"/usr/include" -I"/usr/include/boost" -I"/usr/include/boost/algorithm" -I"/usr/include/boost/thread" -I"/home/rs3lab/workarea-uhd/uhd/host/include/uhd" -I"/home/rs3lab/workarea-uhd/uhd/host/include/uhd/types" -I"/home/rs3lab/workarea-uhd/uhd/host/include/uhd/utils" -I"/home/rs3lab/workarea-uhd/uhd/host/include/uhd/usrp"  -I"/usr/local/MATLAB/R2018a/extern/include" -I"/usr/local/MATLAB/R2018a/simulink/include" -fexceptions -fPIC -fno-omit-frame-pointer -pthread -std=c++11 -O -DNDEBUG "/home/rs3lab/Escritorio/codigos_idepar_C_funcionando/IdeparMexV2.cpp" -o /tmp/mex_420292310722548_10505/IdeparMexV2.o
  CMDLINE1_1 : /usr/bin/g++ -c -DMX_COMPAT_64  -DMATLAB_MEXCMD_RELEASE=R2018a  -DUSE_MEX_CMD   -D_GNU_SOURCE -DMATLAB_MEX_FILE  -I"/usr/include" -I"/usr/include/boost" -I"/usr/include/boost/algorithm" -I"/usr/include/boost/thread" -I"/home/rs3lab/workarea-uhd/uhd/host/include/uhd" -I"/home/rs3lab/workarea-uhd/uhd/host/include/uhd/types" -I"/home/rs3lab/workarea-uhd/uhd/host/include/uhd/utils" -I"/home/rs3lab/workarea-uhd/uhd/host/include/uhd/usrp"  -I"/usr/local/MATLAB/R2018a/extern/include" -I"/usr/local/MATLAB/R2018a/simulink/include" -fexceptions -fPIC -fno-omit-frame-pointer -pthread -std=c++11 -O -DNDEBUG "/usr/local/MATLAB/R2018a/extern/version/cpp_mexapi_version.cpp" -o /tmp/mex_420292310722548_10505/cpp_mexapi_version.o
-------------------------------------------------------------------
Building with 'g++'.
Warning: You are using gcc version '5.5.0'. The version of gcc is not supported. The version currently supported with MEX is '6.3.x'. For a list of
currently supported compilers see: https://www.mathworks.com/support/compilers/current_release. 
/usr/bin/g++ -c -DMX_COMPAT_64  -DMATLAB_MEXCMD_RELEASE=R2018a  -DUSE_MEX_CMD   -D_GNU_SOURCE -DMATLAB_MEX_FILE  -I"/usr/include" -I"/usr/include/boost" -I"/usr/include/boost/algorithm" -I"/usr/include/boost/thread" -I"/home/rs3lab/workarea-uhd/uhd/host/include/uhd" -I"/home/rs3lab/workarea-uhd/uhd/host/include/uhd/types" -I"/home/rs3lab/workarea-uhd/uhd/host/include/uhd/utils" -I"/home/rs3lab/workarea-uhd/uhd/host/include/uhd/usrp"  -I"/usr/local/MATLAB/R2018a/extern/include" -I"/usr/local/MATLAB/R2018a/simulink/include" -fexceptions -fPIC -fno-omit-frame-pointer -pthread -std=c++11 -O -DNDEBUG "/home/rs3lab/Escritorio/codigos_idepar_C_funcionando/IdeparMexV2.cpp" -o /tmp/mex_420292310722548_10505/IdeparMexV2.o
/usr/bin/g++ -c -DMX_COMPAT_64  -DMATLAB_MEXCMD_RELEASE=R2018a  -DUSE_MEX_CMD   -D_GNU_SOURCE -DMATLAB_MEX_FILE  -I"/usr/include" -I"/usr/include/boost" -I"/usr/include/boost/algorithm" -I"/usr/include/boost/thread" -I"/home/rs3lab/workarea-uhd/uhd/host/include/uhd" -I"/home/rs3lab/workarea-uhd/uhd/host/include/uhd/types" -I"/home/rs3lab/workarea-uhd/uhd/host/include/uhd/utils" -I"/home/rs3lab/workarea-uhd/uhd/host/include/uhd/usrp"  -I"/usr/local/MATLAB/R2018a/extern/include" -I"/usr/local/MATLAB/R2018a/simulink/include" -fexceptions -fPIC -fno-omit-frame-pointer -pthread -std=c++11 -O -DNDEBUG "/usr/local/MATLAB/R2018a/extern/version/cpp_mexapi_version.cpp" -o /tmp/mex_420292310722548_10505/cpp_mexapi_version.o
/usr/bin/g++ -pthread -Wl,--no-undefined  -shared -O -Wl,--version-script,"/usr/local/MATLAB/R2018a/extern/lib/glnxa64/c_exportsmexfileversion.map" /tmp/mex_420292310722548_10505/IdeparMexV2.o /tmp/mex_420292310722548_10505/cpp_mexapi_version.o   -lboost_system   -L/usr/lib/x86_64-linux-gnu   -Wl,--as-needed -Wl,-rpath-link,/usr/local/MATLAB/R2018a/bin/glnxa64 -L"/usr/local/MATLAB/R2018a/bin/glnxa64" -Wl,-rpath-link,/usr/local/MATLAB/R2018a/extern/bin/glnxa64 -L"/usr/local/MATLAB/R2018a/extern/bin/glnxa64" -lMatlabDataArray -lmx -lmex -lmat -lm -lstdc++ -o IdeparMexV2.mexa64
Error using mex
/tmp/mex_420292310722548_10505/IdeparMexV2.o: En la función
`MexFunction::operator()(matlab::mex::MexIORange<__gnu_cxx::__normal_iterator<matlab::data::Array*, std::vector<matlab::data::Array,
std::allocator<matlab::data::Array> > > >, matlab::mex::MexIORange<__gnu_cxx::__normal_iterator<matlab::data::Array*, std::vector<matlab::data::Array,
std::allocator<matlab::data::Array> > > >)':
IdeparMexV2.cpp:(.text._ZN11MexFunctionclEN6matlab3mex10MexIORangeIN9__gnu_cxx17__normal_iteratorIPNS0_4data5ArrayESt6vectorIS6_SaIS6_EEEEEESC_[_ZN11MexFunctionclEN6matlab3mex10MexIORangeIN9__gnu_cxx17__normal_iteratorIPNS0_4data5ArrayESt6vectorIS6_SaIS6_EEEEEESC_]+0x331):
referencia a `uhd::device_addr_t::device_addr_t(std::string const&)' sin definir
IdeparMexV2.cpp:(.text._ZN11MexFunctionclEN6matlab3mex10MexIORangeIN9__gnu_cxx17__normal_iteratorIPNS0_4data5ArrayESt6vectorIS6_SaIS6_EEEEEESC_[_ZN11MexFunctionclEN6matlab3mex10MexIORangeIN9__gnu_cxx17__normal_iteratorIPNS0_4data5ArrayESt6vectorIS6_SaIS6_EEEEEESC_]+0x344):
referencia a `uhd::usrp::multi_usrp::make(uhd::device_addr_t const&)' sin definir
collect2: error: ld returned 1 exit status
This is the mex file:
#define _GLIBCXX_USE_CXX11_ABI 0
#include "mex.hpp"
#include "mexAdapter.hpp"
#include <stdlib.h>
//**********************************
#include <uhd/config.hpp> //workarea-uhd/uhd/host/include/uhd
#include <iostream>
#include <stdexcept>
#include <uhd/usrp/multi_usrp.hpp> 
#include <uhd/utils/thread.hpp> 
//#include <uhd/utils/safe_main.hpp>
#include <boost/program_options.hpp> // /usr/include/boost
#include <boost/format.hpp> ////usr/include/boost
#include <boost/algorithm/string.hpp> ////usr/include/boost/algorithm
#include <complex>
#include <chrono>// /usr/include/boost
#include <thread>// /usr/include/boost
#include <boost/lexical_cast.hpp> // /usr/include/boost
#include <boost/config.hpp> // /usr/include/boost
#include <sched.h> 
#include <fstream> 
#include <string.h> 
#include <string> 
#include <uhd/stream.hpp> //workarea-uhd/uhd/host/include/uhd
#include <csignal> 
#include <uhd/exception.hpp> //workarea-uhd/uhd/host/include/uhd
#include <time.h> 
// UDP Socket libraries
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
using namespace std;
using namespace matlab::data;
using matlab::mex::ArgumentList;
using matlab::engine::convertUTF8StringToUTF16String;
class MexFunction : public matlab::mex::Function {
public:
      void operator()(ArgumentList outputs, ArgumentList inputs) {
       /*   
          matlab::data::CharArray = args inputs[0]; //primer argumento IP("args=192.168.40.2")
          matlab::data::CharArray = subdev inputs[1]; //segundo argumento subdev ("A:0 A:1")
          matlab::data::CharArray = channel_list inputs[2]; //tercer argumento  lista de canales ("0,1")
           double freq = inputs[3][0]; //cuarto argumento es la frecuencia ¿?
           double gain = inputs[4][0]; //quinto argumento es la ganancia ¿?
        *
        * outputs[0] = buffer[]; //salida como buffer del canal 1
          outputs[1] = buffer[]; //salida como buffer del canal 2
     */    
          matlab::data::TypedArray<double> in = std::move(inputs[0]);
       std::string args, sync, subdev, channel_list, disp;   
       size_t total_num_samps, num_rx_channels, num_rx_mb;
       double freq, gain, bw, rate;
    int cicles;
       double timed;
    time_t rawtime, timeini, timeend;  /** La clase time_t sirve para tratar elementos temporales*/
        struct tm * timeinfo;      /** Las estructuras de tipo tm tienen datos de caracter temporal desglosados en segundos, minutos....*/
        char buffer [80], buffer_i [80];
//**********************************************************************************************************
//**********************************************************************************************************
//
//      INSERTAR PARÁMETROS
//
//**********************************************************************************************************
//**********************************************************************************************************
          /*
       mexPrintf( "**************************************************************************************************************************\n");
  mexEvalString("drawnow");
        mexPrintf( "                                             IDEPAR 2018                                                    \n");
  mexEvalString("drawnow");
    mexPrintf( "               UNIVERSIDAD DE ALCALA DE HENARES                      \n"); 
  mexEvalString("drawnow");
    mexPrintf( "              DEPARTAMENTO DE TEORIA DE LA SEÑAL                 \n");
  mexEvalString("drawnow");
        mexPrintf( "**************************************************************************************************************************\n");
  mexEvalString("drawnow");
    */  
  args="addr=192.168.40.2";
  total_num_samps=50000000;
  rate=100e6/4;
  bw=rate;
  freq=770e6;
  gain=80;
  sync="now";
  cicles=1;
  timed=0.5;
  subdev="A:0";
  channel_list="0";
time ( &timeini );            // Fijamos en rawtime el instante temporal
timeinfo = localtime ( &timeini );
strftime (buffer_i,80," %H:%M:%S ",timeinfo);
//**********************************************************************************************************
//**********************************************************************************************************
//
//      CREAMOS Y CONFIGURAMOS EL MULTIUSRP Y MULTIDEVICE
//
//**********************************************************************************************************
//**********************************************************************************************************
          //create a usrp device
     //  mexPrintf("Creating the usrp device with: %s...\n", args);
    //  mexEvalString("drawnow");
        uhd::usrp::multi_usrp::sptr usrp = uhd::usrp::multi_usrp::make(args);
  //mexPrintf("Creating the subdevice with: %s...\n", subdev);
//mexEvalString("drawnow");
    //always select the subdevice first, the channel mapping affects the other settings
//        usrp->set_rx_subdev_spec(subdev); //sets across all mboards
//disp=usrp->get_pp_string();
          //mexPrintf("Using Device: %s ...\n",disp);
  //mexEvalString("drawnow");
//num_rx_channels = usrp->get_rx_num_channels();
//  mexPrintf("Número de canales detectados: %f ...\n" , num_rx_channels);
//mexEvalString("drawnow");
//num_rx_mb =  usrp->get_num_mboards();
//        mexPrintf("Número de tarjetas detectadas: %f ...\n" , num_rx_mb);
//mexEvalString("drawnow");
/*mexPrintf( "**************************************************************************************************************************\n");
mexEvalString("drawnow");
mexPrintf( "                                        CLOSING MAIN PROGRAM                                                         \n");
mexEvalString("drawnow");
mexPrintf( "**************************************************************************************************************************\n");
mexEvalString("drawnow");
*/
//return 0;
outputs[0] = std::move(in);
    }
  };
I can't use the mexPrintf funtion neither. Any idea what my fault would be?
Thank you for the help.
Regards, -A
0 Comments
Accepted Answer
  Jason Whitfield
    
 on 19 Jul 2018
        It looks like a linking error to me. The compiler found the headers for the UHD library but not the actual compiled code. Try finding the folder that contains the UHD library object file. The file should have the form "lib<name>.so". Then, add a -L flag to your mex command with the path to the directory containing that file. Also add a -l flag with the name of the library.
As a side note, mex is complaining that your gcc installation is out of date. Try upgrading if possible.
7 Comments
  VINAYAK KARANDIKAR
 on 29 Mar 2019
				Hello Walter,
                      I downloaded the libuhd folder from the github. Now i see 2 folders useful to me:
                      MS 64 and MinGW 64. Each has static and dll subfolders. what do i use here and 
                      how do i use them?
                      Here is my mex comand:
                      I still get the same previous error though. Whats wrong now?
mex -v  -I. ../MATLAB_USRP_INTERFACE/uhdinterface.cpp ../MATLAB_USRP_INTERFACE/tx_functions.cpp ../MATLAB_USRP_INTERFACE/rx_functions.cpp ../MATLAB_USRP_INTERFACE/mexutil.cpp ../MATLAB_USRP_INTERFACE/uhd_functions.cpp ../MATLAB_USRP_INTERFACE/storage.cpp uhd.lib libboost_thread-vc100-mt-1_55.lib libboost_date_time-vc100-mt-1_55.lib libboost_system-vc100-mt-1_55.lib libboost_chrono-vc100-mt-1_55.lib libusb-1.0.lib libusb-1.0.a
  VINAYAK KARANDIKAR
 on 30 Mar 2019
				I got results finally. To close my question: I got the MEX file up. The problem was with the uhd.lib file, which was not getting correctly linked for some reason. I deleted the UHD folder, renstalled the UHD and started all over again. This time the linking (MEX command) worked.
More Answers (0)
See Also
Categories
				Find more on Communications Toolbox in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


