- Open the 'defines.txt' file in the folder and append the flag '-D' before all the macros, with no spaces between the flag and the macro. In newer versions, "defines.txt" is not available anymore. You can get this information by using the "getDefines(buildInfo)" function.
- Then, remove the spacing between all these macros and put them in a single line.
- Copy the names of all the source files in the folder and append them to the line with the macros.
How to compile Windows generated code on a Linux machine?
40 views (last 30 days)
Show older comments
MathWorks Support Team
on 7 Mar 2020
Edited: MathWorks Support Team
on 30 Apr 2025
How can I compile code that has been generated on a Windows machine using Simulink Coder, on a Linux machine?
Accepted Answer
MathWorks Support Team
on 30 Apr 2025
Edited: MathWorks Support Team
on 30 Apr 2025
Update: Starting in R2024a, there is a new workflow to run remote builds with 'slbuild' using CMake and SSH, which would enable you to automate the process of compiling Windows-generated code on a Linux remote computer. For more information, see the R2024a Release Note and the example Build Generated Code Remotely.
Refer to the following two MathWorks documentation pages for more information on relocating generated code to another environment:
You can follow these easy steps to compile Windows-generated code on a Linux machine. This has been tested using Generic Real-Time Target (grt.tlc):
1. Navigate to the Hardware Implementation pane in the model's Configuration Parameters. There, select 'Device Vendor' to be either 'AMD' or 'Intel' and 'Device Type' to be 'x86-64 (Linux 64)'.
2. Navigate to the Code Generation pane. Under 'Build process', enable the options 'Package code and artifacts' and 'Generate Code only'. Also, provide a name in the 'Zip file name' option. This will put all the necessary files needed for compiling in the zip folder. Since only an executable is needed, we can use the Toolchain approach and keep the 'Toolchain' as 'Automatically Installed Toolchain'.
3. Generate C/C++ code from your model (CTRL+B). Then, extract the generated zip folder and navigate inside the folder with the name 'model_grt_rtw'. Here, use the following commands to convert the folder to a flat structure.
>> load buildInfo.mat
>> packNGo(buildInfo);
A new folder with the model name will be generated, which will contain all the files generated by packngo in this single folder.
4. Place this folder on a Linux path and do the following operations:
The end result will look like this:
-DMODEL=vdp -DNUMST=2 .... vdp.c vdp_data.c classic_main.c
5. Then, from a Linux machine where it needs to be compiled, call GCC compiler on the above line:
gcc -DMODEL=vdp -DNUMST=2 .... vdp.c vdp_data.c classic_main.c
An executable should be generated (.out file).
0 Comments
More Answers (0)
See Also
Categories
Find more on Deployment, Integration, and Supported Hardware 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!