Standalone Application Compiler for OSX
Afficher commentaires plus anciens
I'm confused on the process for generating a standalone application for OSX, using Application Compiler.
I've read all the documentation i can find, but was still unclear, and in fact it tends to confuse me more :D Random youtube videos seem to shed the most light -- but perhaps I haven't found the right Matlab documentation.
I'm generating an application, say called Test. It should be a standalone application, so I select "Runtime included in package" (i left the default called MyAppInstaller_mcr) in the Application Compilers, so that everything is included in the package.
My expectation for the result: I can run Test via double click if i copy the executable over, or command line.
But what I get is an application i need to install. Or ifi try and run via cmd line, it requires manually inputting location of the MCR: run_test.sh <path> args.
What am I missing in my understanding of what a standalone application involves?
Is there a way to achieve what I'm trying to, ie copy over a single file to OSX (or linux, etc, depending on what platform i compile on), and just run the executable?
Réponses (1)
Walter Roberson
le 7 Août 2023
0 votes
MATLAB Compiler is not designed to do what you want.
MATLAB Compiler is designed to produce a self-extracting executable that needs to effectively be installed.
In order to create a simple just-copy-and-execute executable you would need to use MATLAB Coder -- which would greatly restrict your ability to use graphics
15 commentaires
John
le 7 Août 2023
Walter Roberson
le 8 Août 2023
The MATLAB Compiler Runtime (MCR) is effectively a separate application that needs to be installed. When you include the runtime in your App and copy the App to a system and run the App there, then the App will detect that MCR is not installed and will need to install it.
In cases where the correct version of MCR is already installed, then no install step is needed: if your target machine already has the right MCR then you can copy your App to it and the App will execute without needing an install step.
Note that the version of MCR must match the version the App was compiled with -- so unfortunately if you already had R2022b MCR installed on a system but started building apps with R2023a then the new apps would need to install a new MCR -- and in some cases when you install an Update (for example R2022b Update 5 when you were running Update 4) then that can end up requiring a new MCR as well.
MATLAB Coder, on the other hand, does not need MCR, and so does not need a separate install step for it.
Walter Roberson
le 8 Août 2023
Unfortunately, nothing in the Symbolic Toolbox can be compiled, and I have not heard of any plans to change that. (I would not go as far as to say it will "never" happen, but I haven't heard any murmurs that Mathworks is working on it.)
I do not have any idea at the moment why compilation is not supported for ordschur()
John
le 8 Août 2023
Walter Roberson
le 8 Août 2023
Neither MATLAB Compiler nor MATLAB Coder can do anything with the Symbolic Toolbox.
The Symbolic Engine runs as a separate process that is communicated with using TCP. The Compiler does not copy in that process, so even if you were able to compile the MATLAB-level code using the symbolic toolbox, there would be a failure the first time you used syms or anything else in the toolbox as even syms requires talking to the separate process.
Walter Roberson
le 8 Août 2023
You might perhaps call into LAPACK directly; https://www.netlib.org/lapack/lawnspdf/lawn171.pdf and https://www.mathworks.com/help/matlab/matlab_external/calling-lapack-and-blas-functions-from-mex-files.html
John
le 8 Août 2023
Walter Roberson
le 8 Août 2023
Modifié(e) : Walter Roberson
le 10 Août 2023
MATLAB Compiler produces a list of functions that you used but which could not be compiled. That list will include everything in the Symbolic Toolbox -- the entire toolbox is blocked from being compiled.
If you loadlibrary() or use the java or C++ interface or you use Simulink S-functions to invoke content inside a DLL... then there is always the possibility that the target system will not have the necessary DLL / shared-object installed.
If you use hardware OpenGL on a Linux system, there is always the possibility that the destination system does not have a compatible vendor OpenGL DLL available.
If you use Linux and build correctly... there is always the possibility that the destination system might be missing some DLL because it is a different distribution, or that it might have an incompatible version of a standard library such as libC.so
If you build on Windows with one of the Microsoft compilers... there is always the possibility that the destination system does not have the required Runtime Redistributable.
Or it could turn out that the destination Windows system does not have a necessary Windows Media codec.
It is pretty uncommon these days for an executable to be truly stand-alone, not reliant on even one component that the operating system considers "optional" -- and not reliant on even one component that has been the target of at least one bug fix or security fix at some point since the time the operating system (such as "Windows 10") was first introduced. You can request "static linking" if you work on it... but statically linked executables are mostly only used for programs or utilities that are intended to be able to execute in Safe Boot.
Walter Roberson
le 10 Août 2023
Toolboxes not supported by MATLAB Compiler include:
- Simulink (and all associated products)
- Simscape, Simevents, and related
- The "blockset" toolboxes
- the "Kit"s
- the Coders
- the Verifiers
- the Servers
- Antenna
- autosar
- Model Based Calibration
- Polyspace related
- RF PCB
- Robust Control
- SerDes
- Signal Integrity
- Requirements
- Symbolic
- System Composer
- ThingSpeak
- HDL related
I might have missed one or two.
Steven Lord
le 10 Août 2023
MATLAB Compiler
MATLAB Compiler generates an application that uses the MATLAB Component Runtime (MCR) instead of MATLAB to run the code that was present in your application when that application was created. It supports a larger subset of the MATLAB language and MathWorks toolboxes than MATLAB Coder does (most notably, many graphics functions work in a MATLAB Compiler generated application.) But not everything is supported for use with MATLAB Compiler, as shown in the link Walter posted. In particular, neither the sym function nor the syms function are supported for use with MATLAB Compiler.
MATLAB Coder
MATLAB Coder generates C or C++ code (and perhaps other languages, I don't remember off the top of my head) from MATLAB code. You don't need the MCR to run that generated code (just a C or C++ compiler), but the subset of the language and toolbox functionality supported for use with MATLAB Coder is smaller than the subset supported with MATLAB Compiler (in particular, I believe few if any of the graphics functions are supported with MATLAB Coder.)
For example, if you filter the list of functions in MATLAB (which lists 325 functions in the Graphics category) by the extended capability "C/C++ Code Generation" only 16 of the Graphics functions have this extended capability. And if you look at them, most are functions that you'd use to import or compute with image data rather than any function to display that data in a figure window. If you look at the list of functions in Symbolic Math Toolbox none support the C/C++ Code Generation extended capability (the Extended Capability filter list doesn't even show up.)
Regarding your other question, can you say a little more about what you are trying to do that requires Symbolic Math Toolbox? Can you perform your calculations symbolically in MATLAB then use matlabFunction to convert the result of those symbolic calculations into a function handle or function file that you can use in your program? If the function created by matlabFunction only uses functionality supported in MATLAB Compiler or MATLAB Coder then that would eliminate this blocking issue for your use of MATLAB Compiler or MATLAB Coder respectively.
syms H [5 5]
syms lam
det_H = det(H - lam * eye(size(H)));
polyn = solve(det_H == 0, lam)
Heig_fun = matlabFunction(polyn, 'file', 'Heig_fun.m', 'vars', {H})
dbtype Heig_fun.m
So now when you arrive at that point in the code, you pass your numeric array H to Heig_fun and get 5 outputs.
Or... you just call eig() on the numeric matrix.
Catégories
En savoir plus sur Code Performance dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

