How can I compile a Linux executable/library from a Simulink model on a Windows machine?
18 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
MathWorks Support Team
il 14 Mar 2025
Modificato: MathWorks Support Team
il 14 Mar 2025
I am trying to compile my Simulink model to a Linux dynamic shared library or executable from a Windows machine. I have tried to select the Linux target option by setting "ProdHWDeviceType" as "x86-64 (Linux 64)", but it was not successful. The Simulink model compiles and builds but the generated executable/library is not callable within the Linux environment.
Is it possible to compile a Simulink model to a Linux library/executable from a Windows machine? How can I do that?
Risposta accettata
MathWorks Support Team
il 14 Mar 2025
Modificato: MathWorks Support Team
il 14 Mar 2025
This workflow is called "cross-compilation" where we are trying to compile code in an environment (host) to be used in another (target).
Code generation and compilation are different processes, the generated code could be platform-independent but the compilation will always be dependent on the environment. The Linux target option mentioned in the question is used for code generation instead of compilation, so it does not affect the build process.
There are a few options to complete this workflow if you are primarily working on a Windows machine, and hope to deploy generated code to run on a Linux system. They are listed as follows (for simplicity, let's say Host is the Windows machine, and Target is the Linux machine):
If MATLAB (including Simulink Coder) is installed on both Host and Target, you can follow the documentation page linked below to generate code on the Host and compile it on the Target.
If you have a SSH connection to the target, and you are using a version of MATLAB from R2024a onwards. You can build the code remotely via an SSH connection. You can follow this documentation for more information: https://mathworks.com/help/releases/R2025a/rtw/ug/build-generated-code-remotely.html
If you have Windows Subsystem for Linux installed and use a MATLAB version from R2025a onwards, you can build code in Windows Subsystem for Linux using CMake. You can find more information about it in the documentation below:
If MATLAB (including Simulink Coder) is only installed on the Host, you can follow the documentation page below with some minor changes in the last section ("Use CMake Configuration Files").
The code to run CMake commands are "system" commands, so they can also be run directly from the command line in a Linux terminal. For instance, you may use the following command to build an executable once you are in the "model_grt_rtw" directory*:
%% ======configure======
/path/to/matlabroot/bin/glnxa64/cmake/bin/cmake .
%% ======compile========
/path/to/matlabroot/bin/glnxa64/cmake/bin/cmake --build .
To build a shared library instead of an executable, you can use the following command to generate "CMakeList.txt" on the Host (the last command in section "Generate Code and CMake Configuration Files"). The rest of the workflow remains the same:
codebuild(buildFolder, 'BuildMethod', 'cmake', 'BuildVariant', 'SHARED_LIBRARY');
* You may need to pass the "MATLAB_ROOT" variable in the CMake configure step as it was previously defined using a Windows path, as the following:
%% ======configure======
/path/to/matlabroot/bin/glnxa64/cmake/bin/cmake -DMATLAB_ROOT="/path/to/matlabroot" .
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Simulink Coder in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!