Simulink coder link order

3 次查看(过去 30 天)
Pascal
Pascal 2022-4-14
回答: Sachin Lodhi 2023-12-19
I am trying to use the Simulink Embedded coder to build the blinking LED app on a Raspberry PI. Everything works except the link fails at the end because it cannot resolve the pthread functions. The generated link command is:

gcc -lrt -lpthread -ldl -o ../test.elf devices.c.o LED.c.o test.c.o test_data.c.o MW_raspi_init.c.o MW_Pyserver_control.c.o linuxinitialize.c.o ert_main.c.o -lm -lm -lstdc++

But it should be:

gcc -lrt -lpthread -ldl -o ../test.elf devices.c.o LED.c.o test.c.o test_data.c.o MW_raspi_init.c.o MW_Pyserver_control.c.o linuxinitialize.c.o ert_main.c.o -lm -lm -lstdc++ -lpthread

With the -lpthread being after the list of .o files. If I execute the second command by hand, the link succeeds and the test runs as expected.
Question: How can I fix that, or how can I add -lpthread after the .o files? I am using Matlab 2022 on a MAC and could not find any way of doing it in the Model Configuration Parameters menu.
Thanks

回答(1 个)

Sachin Lodhi
Sachin Lodhi 2023-12-19
Hi Pascal,
It seems that the linking is failing because the ‘-lpthread’ flag is missing after ‘.o’ files. To resolve this and add ‘-lpthread’ after the object files, you can try the following steps:
  1. Open your model in Simulink.
  2. Go to the ‘Model Configuration Parameters’ by clicking on ‘Model Settings’ in the ‘Modeling’ tab or by pressing Ctrl+E.
  3. Navigate to the ‘Simulation Target’ section.
  4. Select the ‘Code Information’ tab.
  5. In the ‘Code Information’ tab, there are fields for inserting custom code snippets, such as ‘Include directories,’ ‘Source files’, ‘Libraries’, etc.
  6. In the ‘Linker flags’ field, add ‘-lpthread’. This will ensure that ‘-lpthread’ is added at the end of the link command.
Alternatively, you can consider the method outlined in the following MATLAB Answer: https://www.mathworks.com/matlabcentral/answers/109672-how-can-i-add-additional-linker-flags-to-the-generated-makefile
I hope this helps.
Best Regards,
Sachin

类别

Help CenterFile Exchange 中查找有关 Deployment, Integration, and Supported Hardware 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by