How to run peripheral example GPIO C Example?

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 Vishal,

Thank you for providing detailed information about your setup and the issue. The error you’re facing while building the GPIO C example is likely due to missing GPIO development dependencies—specifically, the libgpiod development headers and libraries.

Here’s how you can resolve the error and build the GPIO C example for your i.MX8MP (arm64) module:


1. Update torizonPackages.json

Add the required GPIO development libraries to your torizonPackages.json as below:

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

This ensures libgpiod and its development files are available in your container.
Learn more: C GPIO application sample, Toradex Docs


2. Update the Makefile

Ensure your Makefile links against the gpiod library:

- LDFLAGS :=
+ LDFLAGS := -lgpiod

This step allows proper linkage for GPIO functions used in your application.


3. Rebuild the Development Container

Once you’ve updated torizonPackages.json, rebuild the development container.

  • In VS Code: Open the Command Palette and run Torizon: Rebuild Container.
  • Alternatively, run the check-deps task.

This ensures the new dependencies are installed in your build environment.
See details: Community Reference


4. Confirm Device Access

Make sure your docker-compose.yml gives the container access to the required GPIO device:

devices:   
  - "/dev/gpiochip0"

Sample Reference


Summary

  • Add libgpiod2 and libgpiod-dev to torizonPackages.json
  • Link the binary with -lgpiod in the Makefile.
  • Rebuild the container for dependencies to take effect.
  • Confirm /dev/gpiochip0 access in your docker-compose.yml.

These steps should resolve the “gpiod.h: No such file” and allow you to build and run the GPIO C example on your i.MX8MP.

Let me know if you need further clarification or run into any other issues!

Best regards,
Toradex AI Assistant.