Undefined reference to `gpiod_ctxless_set_value' even with libgpiod2 and libgpiod-dev in torizonPackages.json

I’m getting started with a Qt project using Torizon and am trying to toggle a GPIO. As far as I understand, I should just need to add the libgpiod dependencies to torizonPackages.json, which I think I’ve done correctly:

{
    "deps": [
        "libgpiod2"
    ],
    "devDeps": [
        "libgpiod-dev"
    ]
}

However, when I include gpiod.h in my main.cpp and call gpiod_ctxless_set_value, I get undefined reference to `gpiod_ctxless_set_value’ from the linker.

 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task: cmake -DCMAKE_BUILD_TYPE=Debug -B/home/xxxxxxx/AutoFilteringFixture2/build-local 

-- Configuring done
-- Generating done
-- Build files have been written to: /home/xxxxxxx/AutoFilteringFixture2/build-local
 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task: cmake --build /home/xxxxxxx/AutoFilteringFixture2/build-local 

[  4%] Built target AutoFilteringFixture2_qmlimportscan
[ 17%] Built target AutoFilteringFixture2_tooling
[ 21%] Automatic MOC for target AutoFilteringFixture2
[ 26%] Built target AutoFilteringFixture2_autogen
[ 30%] Running AUTOMOC file extraction for target AutoFilteringFixture2
[ 30%] Built target AutoFilteringFixture2_automoc_json_extraction
[ 34%] Building CXX object CMakeFiles/AutoFilteringFixture2.dir/main.cpp.o
[ 39%] Linking CXX executable bin/AutoFilteringFixture2
/usr/bin/ld: CMakeFiles/AutoFilteringFixture2.dir/main.cpp.o: in function `main':
/home/xxxxxxx/AutoFilteringFixture2/main.cpp:27: undefined reference to `gpiod_ctxless_set_value'
collect2: error: ld returned 1 exit status
gmake[2]: *** [CMakeFiles/AutoFilteringFixture2.dir/build.make:286: bin/AutoFilteringFixture2] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:98: CMakeFiles/AutoFilteringFixture2.dir/all] Error 2
gmake: *** [Makefile:91: all] Error 2

 *  The terminal process "/usr/bin/bash '-c', 'cmake --build /home/xxxxxxx/AutoFilteringFixture2/build-local'" terminated with exit code: 2. 
 *  Terminal will be reused by tasks, press any key to close it. 

Also, as far as I understand, VS Code automation should stick those packages in the various Dockerfile (Dockerfile, Dockerfile.sdk, Dockerfile.debug), but this doesn’t seem to be populating in any of them.

# DO NOT REMOVE THIS LABEL: this is used for VS Code automation
    # __torizon_packages_dev_start__
    # __torizon_packages_dev_end__
# DO NOT REMOVE THIS LABEL: this is used for VS Code automation

What am I missing?

Also here’s my setup:
Apalis iMX6 Quad 2GB IT V1.1Y
Ixora Carrier Board V1.3A
Torizon, using Qt C++/QML Template
Host Machine: Windows, VS Code w/ Torizon IDE Extension 2

I just did a test, when I added the libgpiod packages to my project, the Dockerfiles were not updated right away. Only when I started the build/debug process were these added to my Dockerfiles:

# DO NOT REMOVE THIS LABEL: this is used for VS Code automation
    # __torizon_packages_dev_start__
	libgpiod-dev: \
    # __torizon_packages_dev_end__
# DO NOT REMOVE THIS LABEL: this is used for VS Code automation

As for your “Undefined reference” error. Did you actually link the libgpiod library against your code when you compiled? Or did you just add these packages?

When compiling C/C++ you need to always link libraries as needed against your code for compilation to succeed. Just installing the packages on your system (in a container in this case) does not mean they automatically get linked against your code.

Best Regards,
Jeremias

Good call, I wasn’t linking libgpiod correctly. Thanks for the help!

Glad I was able to assist!