Simulink code error in Arduino IDE

15 ビュー (過去 30 日間)
Federico
Federico 2023 年 4 月 4 日
回答済み: Aravind 2025 年 6 月 24 日 10:48
Hi,
I´m having problems using a .c code generated in simulink in Arduino IDE. My goal is to modify the code in arduino ide and upload it to a Wemos D1 mini. What i did was adding the .c and .h files,generated in simulink. to a zip and adding this zip as a library in the IDE. The last error i had was the following:
15 | # include <dlfcn.h>
| ^~~~~~~~~
compilation terminated.
exit status 1
Compilation error: exit status 1
I would appreciate it if someone knows an easier way to do it.

回答 (1 件)

Aravind
Aravind 2025 年 6 月 24 日 10:48
Hello @Federico,
From your question, it seems that the code generated from Simulink is not compiling in the Arduino IDE due to the missing "dlfcn.h" header file. This is happening because the Arduino IDE cannot find the "dlfcn.h" file, which is typically used in systems running a general operating system. Specifically, it’s part of the GNU C library for dynamic loading of shared libraries, a feature that is generally not required in embedded systems like Arduino or Wemos D1 mini.
Since you haven’t shared your Simulink model file, I suspect that this issue arises because you are generating code using the "grt.tlc" system target file. The "grt.tlc" is designed for generating code for general systems that run an operating system. For embedded systems, such as the Wemos D1 mini, you should use the "ert.tlc" file. The "ert.tlc" is tailored for embedded systems and uses Embedded Coder to generate optimized code, which avoids including header files like "dlfcn.h" that are meant for general systems.
For more information about the different Simulink target files and their uses, you can check this documentation: https://www.mathworks.com/help/rtw/ug/compare-system-target-file-support.html. You can also refer to this MATLAB Answer for additional insights into the difference between using "grt.tlc" and "ert.tlc" as target configuration files: https://www.mathworks.com/matlabcentral/answers/28012-grt-vs-ert.
To resolve your issue, I recommend that you generate code using the "ert.tlc" file instead of "grt.tlc." You can change this in the Model Configuration Parameters under the Code Generation settings. Afterward, you can use the “packNGo” function to gather all necessary source and header files into a zip file. This can be imported into the Arduino IDE, compiled, and uploaded to your Wemos D1 mini. For more details on the "packNGo" function, you can refer to this documentation: https://www.mathworks.com/help/coder/ref/packngo.html.
I hope this helps resolve your issue. If you can share more details about your specific use case and any supporting files, I can provide more focused advice.

カテゴリ

Help Center および File ExchangeArduino Hardware についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by