Good morning,
PROBLEM:
I encountered an error following this tutorial:
Once I did all the steps and tried to compile I got this error:
$ arm-linux-gnueabihf-gcc -o testgpio testgpio.o -g
/usr/lib/gcc-cross/arm-linux-gnueabihf/10/../../../../arm-linux-gnueabihf/bin/ld: testgpio.o: in function `main':
testgpio.c:(.text+0x16): undefined reference to `gpiod_chip_open_by_number'
/usr/lib/gcc-cross/arm-linux-gnueabihf/10/../../../../arm-linux-gnueabihf/bin/ld: testgpio.c:(.text+0x2c): undefined reference to `gpiod_chip_get_line'
/usr/lib/gcc-cross/arm-linux-gnueabihf/10/../../../../arm-linux-gnueabihf/bin/ld: testgpio.c:(.text+0x46): undefined reference to `gpiod_line_request_output'
/usr/lib/gcc-cross/arm-linux-gnueabihf/10/../../../../arm-linux-gnueabihf/bin/ld: testgpio.c:(.text+0x54): undefined reference to `gpiod_line_set_value'
/usr/lib/gcc-cross/arm-linux-gnueabihf/10/../../../../arm-linux-gnueabihf/bin/ld: testgpio.c:(.text+0x62): undefined reference to `gpiod_line_set_value'
collect2: error: ld returned 1 exit status
make: *** [Makefile:8: testgpio] Error 1
The terminal process "/bin/bash '-c', 'make'" terminated with exit code: 2.
DEBUG:
It seems that the library is not loaded during the compilation, indeed the generated Makefile runs:
arm-linux-gnueabihf-gcc -o testgpio testgpio.o -g
TEMP FIX:
The first thing that I tried was to check tasks.json and it was not updated with the option I defined from the GUI by adding devpackages, buildcommands and extrapackages; The only field correctly updated was devpackages, I had to manually write in tasks.json the field buildcommands and extrapackages.
Moreover, to fix this error, I added “-lgpiod” under CFLAGS inside tasks.json such that my debug task looks like:
{
"label": "build_debug",
"command": "make",
"type": "shell",
"args": [],
"problemMatcher": {
"base": "$gcc"
},
"options": {
"env": {
"CFLAGS": "-g -lgpiod",
"CXXFLAGS": "-g -lgpiod"
}
},
"group": {
"kind": "build",
"isDefault": true
}
}
I do not know much about visual studio code and how it handles this stuff, but it seems that there is something not working in the Visual studio code addons for Torizon projects.
ANOTHER PROBLEM
I am now following this tutorial: Qt on Torizon OS | Toradex Developer Center
And I would like to add the gpio handling stuff also here, I tried the same approach as described in the previous tutorial but I got stuck into the same error, even if I add the library to the task.json file, it is ignored when the makefile is generated.
My Makefile make command runs:
arm-linux-gnueabihf-g++ -o appconfig_0/work/testapp/testapp testapp.o qrc_qml.o /usr/lib/arm-linux-gnueabihf/libQt5Quick.so /usr/lib/arm-linux-gnueabihf/libQt5Gui.so /usr/lib/arm-linux-gnueabihf/libQt5QmlModels.so /usr/lib/arm-linux-gnueabihf/libQt5Qml.so /usr/lib/arm-linux-gnueabihf/libQt5Network.so /usr/lib/arm-linux-gnueabihf/libQt5Core.so -lGLESv2 -lpthread
Even if my tasks.json is:
"tasks": [
{
"label": "qmake_debug",
"command": "${env:QMAKE}",
"type": "shell",
"args": [
"CONFIG+=debug"
],
"problemMatcher": {
"base": "$gcc"
},
"options": {
"env": {
"QMAKE_DESTIDIR": "${command:torizon.ccpp.getTargetFolder}",
"CFLAGS": "-g -lgpiod",
"CXXFLAGS": "-g -lgpiod"
}
}
},
{
"label": "build_debug",
"command": "make",
"type": "shell",
"args": [],
"problemMatcher": {
"base": "$gcc"
},
"options": {
"env": {
"CFLAGS": "-g -lgpiod",
"CXXFLAGS": "-g -lgpiod"
}
},
"group": {
"kind": "build",
"isDefault": true
},
"dependsOn": [
"qmake_debug"
]
},
....
EDIT:
TEMP SOLUTION TO SECOND PROBLEM
I just got that the makefile is generated by Qmake and it is possible to assign some parameters from args in tasks.json as it is done with “CONFIG+=debug”. I just added “LIBS += -lgpiod” and now the generated makefile contains that library too.
This is a temporary fix and I believe that this issue needs to be solved by the tool
Someone can explain to me where I can understand a bit more on this stuff?