SIRF and MATLAB - SyneRBI/SIRF GitHub Wiki

Using MATLAB with SIRF

Due to resource limitations, MATLAB support is no longer updated from SIRF v3.3 and likely broken. Apologies for that.

When using MATLAB and SIRF, rhere are a few things you need to be aware of...

Supported MATLAB releases and compilers

If you want to use MATLAB, we strongly advise you to use a compiler supported by MATLAB, check the MathWorks web-site.

Linux

For MATLAB 2018a onwards on Linux your gcc needs to be 6.3,between 2016b and 2017b it is 4.9.2, for (somewhat) older MATLAB versions you need gcc 4.7.2.

Gadgetron needs a gcc version at least 4.8. We therefore recommend to use MATLAB 2016b or more recent. You can try to compile Gadgetron and SIRF with different compilers (but we have not tested this).

You then need to tell CMake which compiler to use. We strongly recommend to do the following before you install SIRF (for instance, for gcc 4.9):

  sudo apt-get install g++-4.9
  export CC=gcc-4.9 
  export CXX=g++-4.9

If you don’t want to use a MATLAB supported compiler, you will have problems (on Linux only?) with shared libraries that MATLAB supplies which are older than the ones you used. See also next point.

You might have problems with shared libraries which you could try to resolve by pre-loading. As an example (but you will need to adapt this to your system):

    LD_PRELOAD=/lib64/libstdc++.so.6:/lib64/libhdf5.so matlab&

Building does not find MATLAB

CMake's FindMatlab.cmake does its best to find the location of your MATLAB but can fail. It’s best to specify this from the start. You can resolve this by creating an environment variable (do this before you run CMake). For instance, on Linux/Mac when using bash

    Matlab_ROOT_DIR=/whereever/Matlab/matlab-R2016b
    export Matlab_ROOT_DIR

You can find the value for the Matlab_ROOT_DIR variable by typing matlabroot on your MATLAB prompt.

MATLAB and Python conflicts

We have encountered problems with either running or building SIRF on systems that have both Python and MATLAB installed due to problems with different versions of the HDF5 libraries (see e.g. #208). If you do have both MATLAB and Python, it might therefore be best to build twice. For instance when building via the SIRF-SuperBuild

cmake -DDISABLE_Matlab:BOOL=ON <other-args> -S ./SIRF-SuperBuild -B ./build_Python
cmake --build ./build_Python --parallel
export CC=gcc9 CXX=g++9 # or whatever the appropriate compiler is for MATLAB
cmake -DDISABLE_Matlab:BOOL=OFF -DDISABLE_PYTHON:BOOL=OFF <other-args> -S ./SIRF-SuperBuild -B ./build_Matlab
cmake --build ./build_Matlab --parallel

Setting the MATLAB path

You will need to add the directory where SIRF installed the MATLAB files to your MATLAB path. For instance, on the MATLAB prompt

    addpath /whereever/INSTALL/matlab

If you installed SIRF and all its dependencies using the SIRF-SuperBuild, then, on Linux or MacOS, the MATLAB path is set by sourcing env_sirf.csh or env_sirf.sh - see SuperBuild installation instructions on Ubuntu and MacOS.

⚠️ **GitHub.com Fallback** ⚠️