cmake findMatlab - location of matlabConfig.cmake or matlab-config.cmake in the MATLAB installation directory

15 次查看(过去 30 天)
I am trying to integrate an external C++ function (large package) into a mex function. I have written a cmake file, which generates library for external C++ function and I am using matlab_add_mex to generate the mex-file.
# Find MATLAB
set(Matlab_ROOT_DIR "../mathworks/2023b/bin/")
find_package(Matlab REQUIRED)
# Add a MEX target
matlab_add_mex(
NAME my_mex_function
SRC my_mex_function.cpp
LINK_TO my_library
)
find_package(Matlab REQUIRED) - gives following error:
CMake Error at CMakeLists.txt: (find_package):
By not providing "Findmatlab.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "matlab", but CMake did not find one.
Could not find a package configuration file provided by "matlab" with any of the following names:
matlabConfig.cmake
matlab-config.cmake
Add the installation prefix of "matlab" to CMAKE_PREFIX_PATH or set "matlab_DIR" to a directory containing one of the above files. If "matlab" provides a separate development package or SDK, be sure it has been installed.
I searched for matlabConfig.cmake or matlab-config.cmake in matlab installation directory but did not find it. Does Matlab provide provide such files or not? If not how to integrate large C++ programs with MATLAB. I dont want to use system function calls as they are too slow.

回答(1 个)

Maneet Kaur Bagga
Hi,
As per my understanding, your error is because "matlabConfig.cmake" file is not provided by MATLAB. The possible workaround for the same is as follows:
Write a MEX function in C++ that interfaces with your shared library. This wrapper will handle data conversion between MATLAB and C++ and manage calls to your library functions. Please refer to the following MathWorks documentation for better understanding.
Alternatively, MATLAB provides a C++ interface that allows you to call functions in a C++ shared library directly from MATLAB. This method involves creating an interface to the library using MATLAB's "clibgen" functionality. Following is the documentation for the same.
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Call C++ from MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by