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

2 次查看(过去 30 天)
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!

回答(1 个)

Pratyush
Pratyush 2024-7-9
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.
  1 个评论
Lili Wei
Lili Wei 2024-7-10
Hello Pratyush,
thanks a lot for summary.
What confuses me is that for C++ generated via the MATLAB Compiler SDK according to the official website,(see hier: compiler sdk) MATLAB is not required.
I have modified mingw64_g++.xml:
  • I made a copy of this .xml files and replaced the MATLABROOT with MATLABRUNTIME.
  • The copy was moved to a similar MATLAB RUNTIME %MATLABRUNTIME%\bin\win64\mexopts\.
  • The mexopts folder doesn't exist in the MATLAB Runtime 2024a folder as it does in MATLAB 2024a. therefore i created manual one.
But the following command can't also find the compiler, also the modified mingw64_g++.xml copy, which located at folder %MATLABRUNTIME%\bin\win64\mexopts.
mex -setup C++ -client MBUILD
After running that, I got the same output as before.
Maybe there is a missing link in the middle for mex -setup C++ -client MBUILD to find available Matlab compilers?From which files does the mex command find available MATLAB compilers? Maybe this is key to solve the problem?
PS.
Also, on a target computer, i installed MATLAB und MATLAB Runtime, if i chose the compiler,e.g following one. I was able to successfully compile and run.
For MinGW64 Compiler (C++): mex -setup:"C:\Program Files\MATLAB\R2024a\bin\win64\mexopts\mingw64_g++.xml" C++ -client MBUILD
But according to the official website, i don't need the MATLAB. If on a target computer, which i only installed MATLAB RUNTIME, i can't find the compiler to compile.
mex -setup C++ -client MBUILD

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 C Shared Library Integration 的更多信息

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by