Device driver (Simulink support package for raspberry Pi) のエラー [-lwiringPi オプションを有効にするには?]

5 views (last 30 days)
以下のドキュメントに沿ってDigital Write blockを作成しようと Step7まで進みましたが実行するとエラーが出ます。ボードはRaspberry Pi 4 B。
wiringPiが正しく読み込めていないのではと推測しますがそれ以上はわかりません。
----12/12追記
RaspberryにてC++でwiringPiを使うコードをビルドした所、上記と同じくundefined referenceエラーが出ますが
ビルドオプションに-lwiringPiを追加すると問題なくビルド出来ます。
-lwiringPiのオプションを指定できれば良いのではと推測します。
-------追記ここまで
----12/12追記その2
-lwiringPiのオプションを指定するにはsimulink coderが必要なようです
私が使っているのはmatlab home ライセンスなのでsimulink coderは購入できません。
-------追記2ここまで
STDERR: /usr/bin/ld: digitalio_raspi.c.o: in function `digitalIOSetup': digitalio_raspi.c:(.text+0x30): undefined reference to `pinMode' /usr/bin/ld: digitalio_raspi.c:(.text+0x40): undefined reference to `pinMode' /usr/bin/ld: digitalio_raspi.c:(.text+0x44): undefined reference to `wiringPiSetupGpio' /usr/bin/ld: digitalio_raspi.c.o: in function `writeDigitalPin': digitalio_raspi.c:(.text+0x58): undefined reference to `digitalWrite' /usr/bin/ld: digitalio_raspi.c.o: in function `readDigitalPin': digitalio_raspi.c:(.text+0x60): undefined reference to `digitalRead' collect2: error: ld returned 1 exit status make: *** [DigitalWriteTest.mk:322: ../DigitalWriteTest.elf]
以下エラー全文
Error executing command "touch -c /home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/Raspi_SimulinkTest/mydriver/DigitalWriteTest_ert_rtw/*.*;make -f DigitalWriteTest.mk all MATLAB_WORKSPACE="/home/pi/MATLAB_ws/R2020b" -C /home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/Raspi_SimulinkTest/mydriver/DigitalWriteTest_ert_rtw". Details: STDERR: /usr/bin/ld: digitalio_raspi.c.o: in function `digitalIOSetup': digitalio_raspi.c:(.text+0x30): undefined reference to `pinMode' /usr/bin/ld: digitalio_raspi.c:(.text+0x40): undefined reference to `pinMode' /usr/bin/ld: digitalio_raspi.c:(.text+0x44): undefined reference to `wiringPiSetupGpio' /usr/bin/ld: digitalio_raspi.c.o: in function `writeDigitalPin': digitalio_raspi.c:(.text+0x58): undefined reference to `digitalWrite' /usr/bin/ld: digitalio_raspi.c.o: in function `readDigitalPin': digitalio_raspi.c:(.text+0x60): undefined reference to `digitalRead' collect2: error: ld returned 1 exit status make: *** [DigitalWriteTest.mk:322: ../DigitalWriteTest.elf] Error 1 STDOUT: make: Entering directory '/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/Raspi_SimulinkTest/mydriver/DigitalWriteTest_ert_rtw' gcc -c -MMD -MP -MF"digitalio_raspi.c.dep" -MT"digitalio_raspi.c.o" -O2 -D__MW_TARGET_USE_HARDWARE_RESOURCES_H__ -DCLASSIC_INTERFACE=0 -DALLOCATIONFCN=0 -DONESTEPFCN=1 -DTERMFCN=1 -DMULTI_INSTANCE_CODE=0 -DINTEGER_CODE=0 -DMT=0 -DTID01EQ=0 -D__linux__ -DARM_PROJECT -D_USE_TARGET_UDP_ -D_RUNONTARGETHARDWARE_BUILD_ -DSTACK_SIZE=64 -DRT -DMODEL=DigitalWriteTest -DNUMST=1 -DNCSTATES=0 -DHAVESTDIO -DMODEL_HAS_DYNAMICALLY_LOADED_SFCNS=0 -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/Raspi_SimulinkTest/mydriver -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/Raspi_SimulinkTest/mydriver/include -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/Raspi_SimulinkTest/mydriver/DigitalWriteTest_ert_rtw -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/extern/include -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/simulink/include -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/rtw/c/src -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/rtw/c/src/ext_mode/common -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/rtw/c/ert -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/SupportPackages/R2020b/toolbox/realtime/targets/raspi/include -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/SupportPackages/R2020b/toolbox/realtime/targets/raspi/server -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/toolbox/coder/rtiostream/src/utils -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/toolbox/target/codertarget/rtos/inc -o "digitalio_raspi.c.o" "/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/Raspi_SimulinkTest/mydriver/src/digitalio_raspi.c" gcc -c -MMD -MP -MF"DigitalWriteTest.c.dep" -MT"DigitalWriteTest.c.o" -O2 -D__MW_TARGET_USE_HARDWARE_RESOURCES_H__ -DCLASSIC_INTERFACE=0 -DALLOCATIONFCN=0 -DONESTEPFCN=1 -DTERMFCN=1 -DMULTI_INSTANCE_CODE=0 -DINTEGER_CODE=0 -DMT=0 -DTID01EQ=0 -D__linux__ -DARM_PROJECT -D_USE_TARGET_UDP_ -D_RUNONTARGETHARDWARE_BUILD_ -DSTACK_SIZE=64 -DRT -DMODEL=DigitalWriteTest -DNUMST=1 -DNCSTATES=0 -DHAVESTDIO -DMODEL_HAS_DYNAMICALLY_LOADED_SFCNS=0 -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/Raspi_SimulinkTest/mydriver -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/Raspi_SimulinkTest/mydriver/include -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/Raspi_SimulinkTest/mydriver/DigitalWriteTest_ert_rtw -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/extern/include -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/simulink/include -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/rtw/c/src -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/rtw/c/src/ext_mode/common -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/rtw/c/ert -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/SupportPackages/R2020b/toolbox/realtime/targets/raspi/include -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/SupportPackages/R2020b/toolbox/realtime/targets/raspi/server -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/toolbox/coder/rtiostream/src/utils -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/toolbox/target/codertarget/rtos/inc -o "DigitalWriteTest.c.o" "/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/Raspi_SimulinkTest/mydriver/DigitalWriteTest_ert_rtw/DigitalWriteTest.c" gcc -c -MMD -MP -MF"DigitalWriteTest_data.c.dep" -MT"DigitalWriteTest_data.c.o" -O2 -D__MW_TARGET_USE_HARDWARE_RESOURCES_H__ -DCLASSIC_INTERFACE=0 -DALLOCATIONFCN=0 -DONESTEPFCN=1 -DTERMFCN=1 -DMULTI_INSTANCE_CODE=0 -DINTEGER_CODE=0 -DMT=0 -DTID01EQ=0 -D__linux__ -DARM_PROJECT -D_USE_TARGET_UDP_ -D_RUNONTARGETHARDWARE_BUILD_ -DSTACK_SIZE=64 -DRT -DMODEL=DigitalWriteTest -DNUMST=1 -DNCSTATES=0 -DHAVESTDIO -DMODEL_HAS_DYNAMICALLY_LOADED_SFCNS=0 -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/Raspi_SimulinkTest/mydriver -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/Raspi_SimulinkTest/mydriver/include -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/Raspi_SimulinkTest/mydriver/DigitalWriteTest_ert_rtw -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/extern/include -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/simulink/include -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/rtw/c/src -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/rtw/c/src/ext_mode/common -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/rtw/c/ert -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/SupportPackages/R2020b/toolbox/realtime/targets/raspi/include -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/SupportPackages/R2020b/toolbox/realtime/targets/raspi/server -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/toolbox/coder/rtiostream/src/utils -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/toolbox/target/codertarget/rtos/inc -o "DigitalWriteTest_data.c.o" "/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/Raspi_SimulinkTest/mydriver/DigitalWriteTest_ert_rtw/DigitalWriteTest_data.c" gcc -c -MMD -MP -MF"MW_raspi_init.c.dep" -MT"MW_raspi_init.c.o" -O2 -D__MW_TARGET_USE_HARDWARE_RESOURCES_H__ -DCLASSIC_INTERFACE=0 -DALLOCATIONFCN=0 -DONESTEPFCN=1 -DTERMFCN=1 -DMULTI_INSTANCE_CODE=0 -DINTEGER_CODE=0 -DMT=0 -DTID01EQ=0 -D__linux__ -DARM_PROJECT -D_USE_TARGET_UDP_ -D_RUNONTARGETHARDWARE_BUILD_ -DSTACK_SIZE=64 -DRT -DMODEL=DigitalWriteTest -DNUMST=1 -DNCSTATES=0 -DHAVESTDIO -DMODEL_HAS_DYNAMICALLY_LOADED_SFCNS=0 -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/Raspi_SimulinkTest/mydriver -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/Raspi_SimulinkTest/mydriver/include -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/Raspi_SimulinkTest/mydriver/DigitalWriteTest_ert_rtw -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/extern/include -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/simulink/include -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/rtw/c/src -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/rtw/c/src/ext_mode/common -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/rtw/c/ert -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/SupportPackages/R2020b/toolbox/realtime/targets/raspi/include -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/SupportPackages/R2020b/toolbox/realtime/targets/raspi/server -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/toolbox/coder/rtiostream/src/utils -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/toolbox/target/codertarget/rtos/inc -o "MW_raspi_init.c.o" "/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/SupportPackages/R2020b/toolbox/realtime/targets/raspi/server/MW_raspi_init.c" gcc -c -MMD -MP -MF"MW_Pyserver_control.c.dep" -MT"MW_Pyserver_control.c.o" -O2 -D__MW_TARGET_USE_HARDWARE_RESOURCES_H__ -DCLASSIC_INTERFACE=0 -DALLOCATIONFCN=0 -DONESTEPFCN=1 -DTERMFCN=1 -DMULTI_INSTANCE_CODE=0 -DINTEGER_CODE=0 -DMT=0 -DTID01EQ=0 -D__linux__ -DARM_PROJECT -D_USE_TARGET_UDP_ -D_RUNONTARGETHARDWARE_BUILD_ -DSTACK_SIZE=64 -DRT -DMODEL=DigitalWriteTest -DNUMST=1 -DNCSTATES=0 -DHAVESTDIO -DMODEL_HAS_DYNAMICALLY_LOADED_SFCNS=0 -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/Raspi_SimulinkTest/mydriver -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/Raspi_SimulinkTest/mydriver/include -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/Raspi_SimulinkTest/mydriver/DigitalWriteTest_ert_rtw -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/extern/include -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/simulink/include -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/rtw/c/src -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/rtw/c/src/ext_mode/common -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/rtw/c/ert -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/SupportPackages/R2020b/toolbox/realtime/targets/raspi/include -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/SupportPackages/R2020b/toolbox/realtime/targets/raspi/server -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/toolbox/coder/rtiostream/src/utils -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/toolbox/target/codertarget/rtos/inc -o "MW_Pyserver_control.c.o" "/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/SupportPackages/R2020b/toolbox/realtime/targets/raspi/src/periphs/MW_Pyserver_control.c" gcc -c -MMD -MP -MF"linuxinitialize.c.dep" -MT"linuxinitialize.c.o" -O2 -D__MW_TARGET_USE_HARDWARE_RESOURCES_H__ -DCLASSIC_INTERFACE=0 -DALLOCATIONFCN=0 -DONESTEPFCN=1 -DTERMFCN=1 -DMULTI_INSTANCE_CODE=0 -DINTEGER_CODE=0 -DMT=0 -DTID01EQ=0 -D__linux__ -DARM_PROJECT -D_USE_TARGET_UDP_ -D_RUNONTARGETHARDWARE_BUILD_ -DSTACK_SIZE=64 -DRT -DMODEL=DigitalWriteTest -DNUMST=1 -DNCSTATES=0 -DHAVESTDIO -DMODEL_HAS_DYNAMICALLY_LOADED_SFCNS=0 -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/Raspi_SimulinkTest/mydriver -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/Raspi_SimulinkTest/mydriver/include -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/Raspi_SimulinkTest/mydriver/DigitalWriteTest_ert_rtw -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/extern/include -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/simulink/include -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/rtw/c/src -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/rtw/c/src/ext_mode/common -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/rtw/c/ert -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/SupportPackages/R2020b/toolbox/realtime/targets/raspi/include -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/SupportPackages/R2020b/toolbox/realtime/targets/raspi/server -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/toolbox/coder/rtiostream/src/utils -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/toolbox/target/codertarget/rtos/inc -o "linuxinitialize.c.o" "/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/toolbox/target/codertarget/rtos/src/linuxinitialize.c" gcc -c -MMD -MP -MF"ert_main.c.dep" -MT"ert_main.c.o" -O2 -D__MW_TARGET_USE_HARDWARE_RESOURCES_H__ -DCLASSIC_INTERFACE=0 -DALLOCATIONFCN=0 -DONESTEPFCN=1 -DTERMFCN=1 -DMULTI_INSTANCE_CODE=0 -DINTEGER_CODE=0 -DMT=0 -DTID01EQ=0 -D__linux__ -DARM_PROJECT -D_USE_TARGET_UDP_ -D_RUNONTARGETHARDWARE_BUILD_ -DSTACK_SIZE=64 -DRT -DMODEL=DigitalWriteTest -DNUMST=1 -DNCSTATES=0 -DHAVESTDIO -DMODEL_HAS_DYNAMICALLY_LOADED_SFCNS=0 -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/Raspi_SimulinkTest/mydriver -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/Raspi_SimulinkTest/mydriver/include -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/Raspi_SimulinkTest/mydriver/DigitalWriteTest_ert_rtw -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/extern/include -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/simulink/include -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/rtw/c/src -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/rtw/c/src/ext_mode/common -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/rtw/c/ert -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/SupportPackages/R2020b/toolbox/realtime/targets/raspi/include -I/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/SupportPackages/R2020b/toolbox/realtime/targets/raspi/server -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/toolbox/coder/rtiostream/src/utils -I/home/pi/MATLAB_ws/R2020b/Applications/MATLAB_R2020b.app/toolbox/target/codertarget/rtos/inc -o "ert_main.c.o" "/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/Raspi_SimulinkTest/mydriver/DigitalWriteTest_ert_rtw/ert_main.c" echo "### Creating standalone executable "../DigitalWriteTest.elf" ..." ### Creating standalone executable ../DigitalWriteTest.elf ... gcc -lrt -lpthread -ldl -o ../DigitalWriteTest.elf digitalio_raspi.c.o DigitalWriteTest.c.o DigitalWriteTest_data.c.o MW_raspi_init.c.o MW_Pyserver_control.c.o linuxinitialize.c.o ert_main.c.o -lm -lm -lstdc++ make: Leaving directory '/home/pi/MATLAB_ws/R2020b/Users/shinji_macpro/Documents/MATLAB/Raspi_SimulinkTest/mydriver/DigitalWriteTest_ert_rtw'
ちなみにStep5では以下の出力結果です。
>> dw = DigitalWrite()
dw =
DigitalWrite with no properties.
digitalio_raspi.cは
ドキュメントのままだと以下のエラーが出るので
error: ‘initialized’ undeclared (first use in this function) if (!initialized) { ^~~~~~~~~~~
int initialized = 0;を追加しています。
#include <wiringPi.h>
#include "digitalio_raspi.h"
int initialized = 0;
void digitalIOSetup(uint8_T pin, boolean_T mode)
{
// Perform one-time wiringPi initialization
if (!initialized) {
wiringPiSetupGpio();
initialized = 1;
}
// mode = 0: Input
// mode = 1: Output
if (mode) {
pinMode(pin, OUTPUT);
}
else
{
pinMode(pin, INPUT);
}
}
// Write a logic value to pin
void writeDigitalPin(uint8_T pin, boolean_T val)
{
digitalWrite(pin, val);
}
// Read a logic value from pin
boolean_T readDigitalPin(uint8_T pin)
{
return ((boolean_T)digitalRead(pin));
}

Answers (0)

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!