Read .mat file using Matlab Runtime(MCR)

9 views (last 30 days)
Filipe
Filipe on 13 Sep 2024
Edited: Filipe on 18 Sep 2024
Hello,
I'm trying to read .mat files in a Qt application. To accomplish this, I need the MAT_LIBRARY. Here's what I've done so far:
  • Installed MATLAB Runtime (MCR)
  • Configured the CMakeLists.txt file to find MATLAB
Here is my CMake configuration to find the MATLAB Runtime:
set(MATLAB_FIND_DEBUG ON)
find_package(Matlab)
include_directories(${Matlab_INCLUDE_DIRS})
target_link_libraries(unit PRIVATE
lib
Matlab::mat)
The problem is that CMake ends with an error and fails to correctly locate MATLAB. Here are some logs from CMake:
-- [MATLAB] Extracting MATLAB versions with registry view args 'VIEW;TARGET'
[cmake] -- [MATLAB] Getting MATLAB roots with registry view args 'VIEW;TARGET'
[cmake] -- [MATLAB] Matlab root folders are MCR;9.13.0.2553342;C:/Program Files/MATLAB/MATLAB Runtime/R2022b/v913
[cmake] -- [MATLAB] Current version is 9.13.0.2553342 located C:/Program Files/MATLAB/MATLAB Runtime/R2022b/v913
[cmake] -- [MATLAB] Determining mex files extensions from 'C:/Program Files/MATLAB/MATLAB Runtime/R2022b/v913/bin' with program 'Matlab_MEXEXTENSIONS_PROG-NOTFOUND'
[cmake] CMake Warning at C:/Program Files/CMake/share/cmake-3.30/Modules/FindMatlab.cmake:686 (message):
[cmake] [MATLAB] Cannot found mexext program. Matlab root is C:/Program
[cmake] Files/MATLAB/MATLAB Runtime/R2022b/v913
[cmake] Call Stack (most recent call first):
[cmake] C:/Program Files/CMake/share/cmake-3.30/Modules/FindMatlab.cmake:1750 (matlab_get_mex_suffix)
[cmake] CMakeLists.txt:61 (find_package)
[cmake]
[cmake]
[cmake] -- [MATLAB] _matlab_lib_prefix_for_search = lib | _matlab_lib_dir_for_search = C:/Program Files/MATLAB/MATLAB Runtime/R2022b/v913/extern/lib/win64/microsoft
[cmake] -- Could NOT find Matlab (missing: Matlab_INCLUDE_DIRS) (found version "9.13.0.2553342")
The MATLAB root folder appears to be "C:/Program Files/MATLAB/MATLAB Runtime/R2022b/v913", but the correct path should be "C:/Program Files/MATLAB/MATLAB Runtime/R2022b". It seems that findMatlab.cmake is adding the version number to the end of the MATLAB root directory. Why is this happening?
[cmake] -- [MATLAB] Extracting MATLAB versions with registry view args 'VIEW;TARGET'
[cmake] -- [MATLAB] Getting MATLAB roots with registry view args 'VIEW;TARGET'
[cmake] -- [MATLAB] Matlab root folders are MCR;9.13.0.2553342;C:/Program Files/MATLAB/MATLAB Runtime/R2022b
[cmake] -- [MATLAB] Current version is 9.13.0.2553342 located C:/Program Files/MATLAB/MATLAB Runtime/R2022b
[cmake] CMake Warning at C:/Program Files/CMake/share/cmake-3.30/Modules/FindMatlab.cmake:686 (message):
[cmake] [MATLAB] Cannot found mexext program. Matlab root is C:/Program
[cmake] Files/MATLAB/MATLAB Runtime/R2022b
[cmake] Call Stack (most recent call first):
[cmake] C:/Program Files/CMake/share/cmake-3.30/Modules/FindMatlab.cmake:1750 (matlab_get_mex_suffix)
[cmake] CMakeLists.txt:61 (find_package)
[cmake]
[cmake]
[cmake] -- [MATLAB] Determining mex files extensions from 'C:/Program Files/MATLAB/MATLAB Runtime/R2022b/bin' with program 'Matlab_MEXEXTENSIONS_PROG-NOTFOUND'
[cmake] -- [MATLAB] _matlab_lib_prefix_for_search = lib | _matlab_lib_dir_for_search = C:/Program Files/MATLAB/MATLAB Runtime/R2022b/extern/lib/win64/microsoft
[cmake] -- Could NOT find Matlab (missing: Matlab_INCLUDE_DIRS) (found version "9.13.0.2553342")
Do you have any ideas?
I’m not using the full MATLAB installation (with my license) because I’m working with developers who don’t have MATLAB. That’s why MATLAB Runtime seemed like a good approach to me.

Answers (1)

Debadipto
Debadipto on 16 Sep 2024
It seems that the MATLAB_ROOT environment variable is not set correctly. Please check if that is the case here. Additionally, you can hardcode the MATLAB path explicitly in your "CMakeLists.txt" as follows:
set(MATLAB_ROOT "C:/Program Files/MATLAB/MATLAB Runtime/R2022b")
Hope this helps!
  1 Comment
Filipe
Filipe on 18 Sep 2024
Edited: Filipe on 18 Sep 2024
The MATLAB_ROOT variable is correctly set in my registry.
MATLABROOT : C:\Program Files\MATLAB\MATLAB Runtime\R2022b
I think there is a problem with the findMatlab.cmake.
Have you used find_package(Matlab) with the MCR installation ?

Sign in to comment.

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!