Simple c gpio project - cannot find gpiod.h

Dear Toradex Community,
I am trying to get a most basic gpio sample to work on a Verdin AM62 SoM on a Dahlia board.
I have Win11, with VSCode running, using WSL. The SoM runs Torizon OS.

Before I followed How to Use GPIO on Torizon OS | Toradex Developer Center and a could download and run the pre-compiled container to test access to the GPIO pins.

I made a python script run, and am now trying a C/C++ Makefile Project, which I changed to C and use the GCC (as the README explained).

I added to the docker-compose.yml: (for both “services” gpiotest10-debug: and gpiotest10, as i named my project gpiotest10)
devices:
- “/dev/gpiochip0”

In the makefile, i added " -lgpiod" to the LDFLAGS

i simply copied the code from the sample on git:

and i replaced in launch.json:
“sourceFileMap”: {
“${config:torizon_app_root}”: “${workspaceFolder}”
},
with
“sourceFileMap”: {
“/home/torizon/app”: “${workspaceFolder}”
},
To solve the “Cannot read properties of undefined (reading ‘replaceAll’)” error.

Now after clicking “Start Debugging” button (for Torizon arm64) in the Run and Debug - Area, i still get
“arch64-linux-gnu-gcc -Iincludes/ -c -g -o build-arm64/debug/main.o src/main.c
src/main.c:2:10: fatal error: gpiod.h: No such file or directory
2 | #include <gpiod.h>
| ^~~~~~~~~
compilation terminated.
make: *** [Makefile:44: build-arm64/debug/main.o] Error 1”

Do i have to manually copy the header file into the “include” folder of the project? I cannot find it in the sample c GPIO project. Do i have to install the libgpiodev library in WSL? How can i properly include the library?

Any help would be appreciated.
Kind regards,
Dom

Hi, I’m the Toradex AI Assistant.

I might make mistakes. Our support team will step in if needed. If I answered your question, please tick the “Solution” checkbox. For follow-up questions to me, please use @ToradexAI in your post.

Did you like my answer? :+1: :-1:


Hello Dom,

Thank you for your detailed explanation! You do not need to manually copy the gpiod.h header into your project or install the GPIO development library in WSL. Instead, all dependencies should be handled inside the container during the build process. The error you’re seeing indicates that the development container is missing the required package to provide gpiod.h.

Here’s how to configure your project for proper dependency management:

1. Update torizonPackages.json

Add the following dependencies to your torizonPackages.json file so the development container includes the GPIO headers and libraries:

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

Reference: How to Use GPIO on Torizon OS | Toradex Developer Center

2. Update Your Makefile

It’s correct to have -lgpiod in your LDFLAGS. For example:

CC := gcc
CCFLAGS := -Iincludes/
DBGFLAGS := -g
LDFLAGS := -lgpiod
CCOBJFLAGS := $(CCFLAGS) -c
ARCH :=

Reference: C Example Makefile

3. Confirm Device Access in docker-compose.yml

In your docker-compose.yml, ensure /dev/gpiochip0 is accessible for your services. Example:

devices:
  - "/dev/gpiochip0"

Or, for broader access during debugging:

volumes:
  - type: bind
    source: /dev
    target: /dev
device_cgroup_rules:
  - "c 254:* rmw"

Reference: Docker Compose Peripheral Access

4. Rebuild Your Development Container

After updating torizonPackages.json, you need to rebuild the development container so the new dependencies are installed.

  • In VS Code, open the Command Palette and run Torizon: Rebuild Container or
  • Run the check-deps task via VS Code Task Runner.

5. No Local Installation Required

You do not need to install libgpiod-dev on your WSL or manually copy header files. The VS Code Torizon extension manages dependencies inside the container automatically.

Summary

In summary, just update torizonPackages.json, verify your Makefile and docker-compose.yml, and rebuild your dev container. This will make gpiod.h available during compilation.

Detailed step-by-step:

Let me know if this gets you past the gpiod.h not found error or if you need further assistance!

Best regards,
Toradex AI Assistant.

Hey @domi471!

I believe the main problem is that you need to install libgpiod-dev inside your container to be able to use the C API for GPIO. Following ToradexAI should solve the problem, particularly step 1. Let me know if it works.

In addition to that, I would suggest reading our GPIO Example in C using the IDE Extension to get a more in-depth explanation of how to set up the IDE for a C project.

Best regards,

Dear leonardo,
thank you for the fast response!
It worked out now and it seems i had an issue in the torizonPackages.json file.
It should look like this:

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

but i had another structure (by default) and the following worked fine:
{
“buildDeps”: [
“libgpiod-dev”
],
“prodRuntimeDeps”: [
“libgpiod2”
],
“devRuntimeDeps”: [
“libgpiod-dev”
]
}

PS: I didnt have to install a library inside the container.

Kind regards,
Dominik

Hey, @domi471,

I’m glad you managed to solve the problem! I’ll be marking the AI answer as the solution.

Best regards,