Failed to Initialize MATLAB R2023b Runtime Library in Visual Studio 2019 C++ Project

13 views (last 30 days)
I generated a C shared library type DLL for a custom function using the MATLAB Library Compiler and created a console C++ project in Visual Studio 2019 to call the DLL function and continue development. However, when initializing the DLL function, it reports a failure. I have set the PATH in the system environment variable to D:\Program Files\MATLAB\MATLAB Runtime\R2023b\bin\win64, and I have also set the include and library directories in Visual Studio 2019, and entered as many MATLAB runtime libraries as possible in the linker: mclmcr.lib; mclmcrrt.lib; libmat.lib; libmex.lib; libmx.lib; along with the custom .lib file. Why is the runtime library initialization still failing? My MATLAB version is R2023b, the compiler version is 23.2, and the runtime library version is 23. What could be causing the runtime library initialization to fail?

Answers (1)

Harsh
Harsh on 27 Aug 2024
From what I can gather, you are trying to set up MS Visual Studio along with MATLAB for C++ development in windows and are facing issues in the process.
Here’s how you can achieve the same:
  • Go to the properties of your project node.
  • Make sure the platform is set to x64:
  • Under C/C++ > General, add the following directory to the Additional Include Directories field:
C:\Program Files\MATLAB\MATLAB Runtime\R2023b\extern\include
  • Under Linker > General, add the following directory to the Additional Library Directories field:
C:\Program Files\MATLAB\MATLAB Runtime\R2023b\extern\lib\win64\microsoft
  • Under Linker > Input, add the following libraries to the Additional Dependencies field.
Add delayimp.lib; libMatlabCppSharedLib.lib; libMatlabDataArray.lib along with mclmcr.lib; mclmcrrt.lib; libmat.lib; libmex.lib; libmx.lib;
After which you can include the relevant headers and the build in release and x64.
Refer the following MathWorks document to learn more:
I hope this helps, thanks!

Categories

Find more on C Shared Library Integration in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!