If I only have MATLAB Runtime, e.g 2024a, can i run mbuild in a compiled cpp file using either the C++ Data Array or mwArray APIs,which generated by C++ Shared Library
6 views (last 30 days)
Show older comments
I want to use the program supported by C++ shared libraries created by The Library Compiler in MATLAB® Compiler SDK™. But I have problem on configuration.
The MATLAB code was compiled using the 2024a MATLAB® .
I've tried installing only runtime 2024a and the needed compiler MinGW 8.1, along with the Windows SDK, but I still can't run the .cpp file, either using the C++ Data Array or mwArray APIs.
I've also already set up the environment variable for the compiler.
Only I installed the MATLAB 2024a, I can succeed in configuration.
What I did is the following in the command window:
mbuild -setup
It shows that MBUILD is configured to use 'MinGW64 Compiler(C)' to compile C files.
And I can choose the following command to compile another language.
mex -setup C++ -client MBUILD
After that, there are two compilers available.
For MinGW64 Compiler (C++): mex -setup:"C:\Program Files\MATLAB\R2024a\bin\win64\mexopts\mingw64_g++.xml" C++ -client MBUILD
For MinGW64 Compiler with Windows 10 SDK or later (C++): mex -setup:C:\Users\12146\AppData\Roaming\MathWorks\MATLAB\R2024a\MBUILD_C++_win64.xml C++ -client MBUILD
If MinGW64 Compiler (C++) is set, the generation of both .exe for the .cpp using C++ Data Array and mwArray APIs can work.
However, if MinGW64 Compiler with Windows 10 SDK or later (C++) is set, only the .exe file using mwArray APIs works.
That's strange, i don't know why it's that.
What I really want to ask is:
Is there a file in MATLAB Runtime similar to mingw64_g++.xml?
Or can I the modify the mingw64_g++.xml, in order to link to the runtime?
<env
PATH = "$MINGWROOT\bin;$MATLABROOT\extern\include\$ARCH;$MATLABROOT\extern\include;$MATLABROOT\simulink\include;$MATLABROOT\lib\$ARCH"
Then I can use mbuild the .cpp file only supported by MATLAB Runtime?
Thank you!
0 Comments
Answers (1)
Pratyush
on 9 Jul 2024
Hi Lili,
You are facing issues configuring MinGW to work with MATLAB Runtime for compiling C++ files using MATLAB Compiler SDK. Here’s a summary of the steps to resolve this:
Verify that MATLAB Runtime 2024a is installed.
Modify mingw64_g++.xml:
- Update the XML file to include paths to MATLAB Runtime libraries and headers.
Set Environment Variables:
- Ensure environment variables point to MATLAB and MATLAB Runtime.
set MATLABROOT=C:\Program Files\MATLAB\R2024a
set MATLABRUNTIME=C:\Path\To\MATLAB\Runtime\R2024a
set PATH=%MATLABROOT%\bin\win64;%MATLABRUNTIME%\bin\win64;%PATH%
Compile Using mbuild:
- Use 'mbuild' and 'mex' to set up and compile.
mbuild -setup
mex -setup C++ -client MBUILD
mbuild yourfile.cpp
- Ensure compatibility between MinGW, MATLAB, and MATLAB Runtime versions.
- Verify all dependencies and libraries are accessible.
- Check for necessary permissions.
Hope this helps.
See Also
Categories
Find more on MATLAB Compiler SDK in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!