How do I use the MATLAB Compiler to generate an EXE that can call the Statistics Toolbox?

6 次查看(过去 30 天)
Greetings,
I am using the MATLAB compiler to create a Monte Carlo simulation that is sent to a cluster. When I compile the MC simulation into a standalone exe, I can run it on my workstation, and I can run it on another machine that has MATLAB installed. But when I send the compiled executable to the cluster, as an EXE, I get this error when I run the executable on the command line:
Unrecognized function or variable 'unifrnd'
Here is how I am compiling the executable with MCC:
mcc -mv -R singleCompThread -R -nodisplay -R -nojvm montecarlo.m
I have the correct runtime installed on the cluster machine, for R2020b (I think). But, I had to add two directories from the runtime installation to the system PATH manually to get the code to run. These are the two entries from the PATH:
C:\Program Files\MATLAB\MATLAB Runtime\v99\lib\win64;C:\Program Files\GnuWin32\bin;C:\Program Files\GnuWin32\lib\win64
If I manually restore my default path in MATLAB, then exit and rebuild the standalone EXE, it doesn't seem to help.
From what I have read, the Statistic Toolbox is supported by the MATLAB compiler. Also, if a toolbox is supported, it should be automatically found by MCC and appropriately packaged in the EXE.
Does anyoneone have any tips for how to solve or debug this problem using the MATLAB compiler?
Thanks!
-Ben
  3 个评论
Matt
Matt 2023-8-9
I had a similar issue, except with the raylrnd function:
factor = ( 1 - x ) + x * raylrnd( 1, 1, N ) / sqrt( pi/2 );
I'm running Matlab 2019a (9.6.0.1072779) with Statistics and Machine Learning Toolbox Version 11.5 on both Windows 10 Enterprise Version 10.0 (Build 19045) and Linux 3.10.0-1160.88.1.el7.x86_64. I'm using MCR v96 on both systems; on Windows the Version.xml file indicates version 9.6.0.1072779 while in Linux it's 9.6.0.1472908. I'm using MCR "Update 9" on Linux.
Similar to the OP my code runs fine in both operating systems when running in Matlab, but the compiled version throws an "Undefined function or variable 'raylrnd'" error in both systems when it hits the line above while running compiled code. I had to manually add the path to the statistics toolbox in the compile command:
statToolboxDir = fileparts( which( 'raylrnd' ) );
mcc( '-a', statToolboxDir, 'RunMyCode.m' );
I had to do something similar for the Mapping and Simulink 3D toolboxes, even though they are supposed to be supported by the compiler. I'm fairly confident, but not 100% sure, that the function calls that cause me problems all occur within private or protected methods on handle class objects. Maybe that has something to do with it?
Steven Lord
Steven Lord 2023-8-9
I'm fairly confident, but not 100% sure, that the function calls that cause me problems all occur within private or protected methods on handle class objects. Maybe that has something to do with it?
How are those objects created? Do you call the constructor in your code or do you obtain all the instances of those objects by loading a MAT-file?
If you are attempting to compile code using MATLAB Compiler that calls load to load an object from a MAT-file and there is no indication in the code itself that MATLAB Compiler needs to package the code, the dependency analyzer may not be able to detect that it needs to include the definition of the class. In this case use one of the workarounds in the "Fixing Callback Problems: Missing Functions" section of this documentation page, as this workflow is described by the Tip in that section of that documentation page.

请先登录,再进行评论。

回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by