How to set Configurations in VS Code C++ QT with widget based UI to access the references from gpiod.h header?

Please refer to the simple project source code attached.
When stared the debugging the error: “workspaces/QT_TEST_2/mainwindow.cpp:22: undefined reference to `gpiod_chip_open_by_number” is reported. Is it possible to set configuration to make gpiod.h work with QT widgets ?

link text

Greetings @Serghey,

Probably the most straight-forward way to accomplish this would be to modify the project’s .vscode/tasks.json file. This file has project specific definitions, for certain actions including compilation. Try adding -lgpiod flag to the build/compile command in this file. This should link the appropriate libraries during compilation.

Furthermore i believe tasks definition are separate for build and debug configurations. So make sure to change both.

Best Regards,
Jeremias

Hello Jeremias,
Thank you for the reply. Could you provide the example where -lgpiod should be added in task.json file? Please refer below.

{
“version”: “2.0.0”,
“tasks”: [
{
“label”: “qmake_debug”,
“command”: “${env:QMAKE}”,
“type”: “shell”,
“args”: [
“CONFIG+=debug”
],
“problemMatcher”: {
“base”: “$gcc”
},
“options”: {
“env”: {
“QMAKE_DESTIDIR”: “${command:torizon.ccpp.getTargetFolder}”
}
}
},
{
“label”: “build_debug”,
“command”: “make”,
“type”: “shell”,
“args”: ,
“problemMatcher”: {
“base”: “$gcc1”
},
“group”: {
“kind”: “build”,
“isDefault”: true
},
“dependsOn”: [
“qmake_debug”
]
},
{
“label”: “qmake_release”,
“command”: “${env:QMAKE}”,
“type”: “shell”,
“args”: ,
“problemMatcher”: {
“base”: “$gcc”
},
“options”: {
“env”: {
“QMAKE_DESTIDIR”: “${command:torizon.ccpp.getTargetFolder}”
}
}
},
{
“label”: “build_release”,
“command”: “make”,
“type”: “shell”,
“args”: ,
“problemMatcher”: {
“base”: “$gcc”
},
“group”: “build”
},
{
“label”: “clean”,
“command”: “make”,
“type”: “shell”,
“args”: [
“clean”
],
“problemMatcher”: {
“base”: “$gcc”
},
“group”: “build”,
“dependsOn”: [
“qmake_debug”
]
},
{
“detail”: “deploy application to work folder”,
“label”: “deploy”,
“command”: “make”,
“args”: [
“install”
],
“type”: “shell”,
“group”: “none”
}
],
“options”: {
“env”: {
“TORIZON_PROP_ARG”: “ARG SSHUSERNAME=#%application.username%#\n”,
“TORIZON_PROP_APPNAME”: “QT_TEST_2”,
“TORIZON_PROP_BUILDCOMMANDS”: “RUN usermod -a -G gpio torizon”,
“TORIZON_PROP_BUILDFILES”: “”,
“TORIZON_PROP_COMMAND”: “”,
“TORIZON_PROP_DEVPACKAGES”: “libgpiod-dev:armhf libgpiod2:armhf”,
“TORIZON_PROP_ENV”: “”,
“TORIZON_PROP_EXENAME”: “QT_TEST_2”,
“TORIZON_PROP_EXPOSE”: “”,
“TORIZON_PROP_EXTRAPACKAGES”: "libgpiod2 gpiod libqt5widgets5 ",
“TORIZON_PROP_LANGUAGE”: “c-cpp-nossh”,
“TORIZON_PROP_PREINSTALLCOMMANDS”: “”,
“TORIZON_PROP_SDKPOSTINSTALLCOMMANDS”: “”,
“TORIZON_PROP_SDKPREINSTALLCOMMANDS”: “”,
“TORIZON_PROP_TARGETCOMMANDS”: “”,
“TORIZON_PROP_TARGETFILES”: “”
}
}
}

Actually since you’re using a Qt based project this is actually a bit simpler. In your project folder there should be a *.pro file. You can define additional external libraries here.

The syntax should look like this: Creating Project Files | qmake Manual

So for your case it should be something like this:

LIBS += -L/usr/lib/aarch64-linux-gnu -lgpiod

Then when this file gets processed it should setup the Makefile such that the gpiod library gets linked. Though double-check the generated Makefile just to make sure.

By the way when I was reviewing your project files I noticed something odd. For your devpackages you used an architecture of armhf but here in your question you listed that you’re on the Colibri i.MX8X, which is arm64. Which is it?

Best Regards,
Jeremias

Great it works!

Thank you so much!

Regarding of armhf/armf64 … we just tried and it works for both.

Best regards.

Glad it works. Also arm64 architecture can use both arm and arm64 binaries but it’s strongly suggested to stick to the right architecture to avoid possible strange issues.

Best Regards,
Jeremias