Why does generating code for Intel x86-64 Linux targets include Windows header functions in code generated by Embedded Coder with MATLAB R2022b?

 I am trying to generate code for a Linux target from a Windows machine using Embedded Coder in MATLAB R2022b.
I have a model that is configured to execute concurrently on multiple Intel x86-64 Linux cores. Hence, performing code generation from those models generates codes containing Mutex locks and semaphores. The issue arises that all the functions used to implement the locks and semaphores uses windows functions as contained in "rtw_windows.h".
However, since my end goal is to deploy it to a Linux target, I need to be able to replace these functions with their POSIX counterparts so that I can build them on Linux targets.
How can I achieve this workflow?

 Accepted Answer

This workflow can usually be achieved using a "Code Replacement Library" (CRL).
Note that below workaround works only with Embedded Coder as using CRLs is only available in Embedded Coder. 
However, as of MATLAB R2022b, changing the "Hardware Implementation" to "Intel x86-64 (Linux)" and the "Code Replacement Library" to Linux libraries does not achieve the needed workflow.
In order to achieve the above workflow (POSIX style of implementing data synchronization and mutex locks) you can use the attached CRL which will swap the Windows functions used for their POSIX counterpart. To use the attached CRL, please follow the steps below:
  1. Download the files "rtw_linux_tfl_table_tmw.m" and "rtw_linux_table_tmw.mat".
  2. Execute the command "crtool" in MATLAB Command line.
  3. In the "Code Replacement - Manage Libraries" app that is opened, click on "Open" on the upper left corner and select "rtw_linux_code" in the Code Replacement Tool.
  4. Click on "Generate Registration File" and add it to a folder on your MATLAB Path give the replacement register a name like "linux_semaphore".
  5. Type and run "sl_refresh_customizations" in the MATLAB command line.
  6. In your model settings go to Code Generation/Interface and click on "Select" on the "Code Replacement libraries" line.
  7. You should see an "linux_semaphore" entry (or whatever you named your file), click on it and click on the right arrow. 
  8. You should see "linux_semaphore" next to "Code Replacement Libraries". Generate code, and it should not use Windows functions.
Please ensure that you have downloaded both the M file and the MAT file in the same location. Also, ensure that before code generation, you have chosen the following values in the "Configuration Parameters > Hardware Implementation" pane:
  • Device vendor = "Intel"
  • Device type = "x86-64 (Linux 64)"
Please note that this CRL is tested for the above vendor and type combination. In case of a different combination, please keep in mind that this CRL might be susceptible to failure in corner cases. 
Please refer to the CRL documentation for further information on using developing and using Code Replacement Libraries.

More Answers (0)

Products

Release

R2022b

Community Treasure Hunt

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

Start Hunting!