필터 지우기
필터 지우기

Simulink coder link order

조회 수: 4 (최근 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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by