Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ source compilation using MATLAB Engine and g++

It would be helpful if you could provide some guidance on how to compile c++ source code files in an Ubuntu environment, using the MATLAB Engine with g++.

like image 247
obelix Avatar asked Mar 21 '17 20:03

obelix


1 Answers

I assume that you want to know the procedure for compiling the c++ code (which calls MATLAB engine) using g++ from Linux Terminal. To do so, follow the steps below:

  1. Include following paths in PATH variable:

    a) Location of MATLAB i.e. $matlabroot/bin b) $matlabroot/sys/os

    You can do this by using the command 'setenv PATH $matlabroot/bin:$matlabroot/sys/os:$PATH ' .

  2. In the command prompt, navigate to the directory where the cpp code is located using cd command. For instance, if you are compiling engdemo.cpp, you need to navigate to $matlabroot/extern/examples/eng_mat/engdemo.cpp

  3. You need to call the compiler with required include files and libraries. For this you can use -I and -L switches for that. Note that the order is important. So you need to use the command as below:

    g++ engdemo.cpp -I "$matlabroot/extern/include" -L "$matlabroot/bin/glnxa64" -leng -lmat -lmex -lut -o engdemo.o

  4. The above command will generate an object file engdemo.o. To execute this, use the command ./engdemo.o

    You can refer to the document at http://www.umiacs.umd.edu/~jsp/Downloads/MatlabEngine/MatlabEngine.pdf for more help regarding C++ and MATLAB.

like image 66
Sonam Gupta Avatar answered Oct 07 '22 23:10

Sonam Gupta