How to run peripheral example GPIO C Example?

Hello All,

I am using iMX8MP and on windows laptop run ubuntu virtual Linux. I referred this link for GPIO Example and GitHub C Code: LINK

All required setup I did and successfully ran hello example. But when i tried to build this GPIO C example getting below error:

Please help me how build successfully for arm64 architecture?

Thank you in Advanced.
Vishal

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.

Hey @vishalborle92,

Can you run the task runner commands try-update-template-accepting-all and check-deps download all the is required, and then run the build command again? Also can you post the full logs rather than a screenshot.

Thanks

-Eric

Hello Eric.tx,
Thanks for prompt response.

I verified all things that Toradex AI said looks correct to me. then tried to run try-update-template-accepting-all but getting errors attached full log for your reference…

Container Runtime: docker
Run Arguments: --rm --privileged torizon/binfmt
Container Name: binfmt
Error response from daemon: No such container: binfmt
Container does not exist. Starting ...
*  Terminal will be reused by tasks, press any key to close it. 

You are about to accept all incoming changes from the updated template
If the project is not versioned there is no way back
Accept all changes? [y/n]: y
Copy-Item: /home/vishal/gpio/C/gpioC/.conf/projectUpdater.ps1:105:1
Line |
105 |  Copy-Item `
    |  ~~~~~~~~~~~
    | Cannot find path '/home/vishal/.apollox/cConsole/.conf/update.json' because it does not exist.

*  The terminal process "pwsh '-nop', '/home/vishal/gpio/C/gpioC/.conf/projectUpdater.ps1', '/home/vishal/gpio/C/gpioC', 'gpioC', '1'" terminated with exit code: 1. 
*  Terminal will be reused by tasks, press any key to close it. 

*  Executing task: DOCKER_HOST= docker build --pull -f /home/vishal/gpio/C/gpioC/Dockerfile.sdk /home/vishal/gpio/C/gpioC -t cross-toolchain-arm64-gpioc --build-arg IMAGE_ARCH=arm64 --build-arg GPU= --build-arg APP_ROOT=/home/torizon/app 

[+] Building 2.2s (8/8) FINISHED                                                                                                              docker:default
=> [internal] load build definition from Dockerfile.sdk                                                                                                0.0s
=> => transferring dockerfile: 1.07kB                                                                                                                  0.0s
=> WARN: InvalidDefaultArgInFrom: Default value for ARG torizon/debian-cross-toolchain-${IMAGE_ARCH}:${CROSS_SDK_BASE_TAG} results in empty or invali  0.0s
=> [internal] load metadata for docker.io/torizon/debian-cross-toolchain-arm64:3.3.0-bookworm                                                          2.1s
=> [internal] load .dockerignore                                                                                                                       0.0s
=> => transferring context: 56B                                                                                                                        0.0s
=> [1/4] FROM docker.io/torizon/debian-cross-toolchain-arm64:3.3.0-bookworm@sha256:46b730261b75685dd8bd454f295114bc1dfcd85f6e8f077b97bb57d719f033fd    0.0s
=> CACHED [2/4] RUN apt-get -q -y update &&     apt-get -q -y install     &&     apt-get clean && apt-get autoremove &&     rm -rf /var/lib/apt/lists  0.0s
=> CACHED [3/4] RUN apt-get -q -y update &&     apt-get -q -y install  libgpiod-dev:     &&     apt-get clean && apt-get autoremove &&     rm -rf /va  0.0s
=> CACHED [4/4] WORKDIR /home/torizon/app                                                                                                              0.0s
=> exporting to image                                                                                                                                  0.0s
=> => exporting layers                                                                                                                                 0.0s
=> => writing image sha256:892c7a076563ebb070fe0c7087e138031c6cd4d0ffaf09ca3495d92b76cfb6ea                                                            0.0s
=> => naming to docker.io/library/cross-toolchain-arm64-gpioc                                                                                          0.0s

1 warning found (use docker --debug to expand):
- InvalidDefaultArgInFrom: Default value for ARG torizon/debian-cross-toolchain-${IMAGE_ARCH}:${CROSS_SDK_BASE_TAG} results in empty or invalid base image name (line 16)
*  Terminal will be reused by tasks, press any key to close it. 

*  Executing task: make ARCH=arm64 makedir 

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

*  Executing task: DOCKER_HOST= docker run --rm -v /home/vishal/gpio/C/gpioC:/home/torizon/app cross-toolchain-arm64-gpioc make ARCH=arm64 CC=aarch64-linux-gnu-gcc debug 

aarch64-linux-gnu-gcc -Iincludes/ -g build-arm64/debug/main.o -o build-arm64/debug/gpioC -lgpiod
/usr/lib/gcc-cross/aarch64-linux-gnu/12/../../../../aarch64-linux-gnu/bin/ld: cannot find -lgpiod: No such file or directory
collect2: error: ld returned 1 exit status
make: *** [Makefile:47: build-arm64/debug/gpioC] Error 1

*  The terminal process "/usr/bin/bash '-c', 'DOCKER_HOST= docker run --rm -v /home/vishal/gpio/C/gpioC:/home/torizon/app cross-toolchain-arm64-gpioc make ARCH=arm64 CC=aarch64-linux-gnu-gcc debug'" terminated with exit code: 2. 
*  Terminal will be reused by tasks, press any key to close it. 

Thanks,
Vishal

Hey @vishalborle92,

And can you run the check-deps task runner and post the logs?

Thanks

Hi @eric.tx

I just ran check-deps task below log:

Checking dependencies ...
👍 openssh-client debian package dependency installed
👍 sshpass debian package dependency installed
👍 build-essential debian package dependency installed
👍 make debian package dependency installed
👍 gdb debian package dependency installed
👍 gcc debian package dependency installed
✅ All packages already installed and installation scripts executed before for this project
 *  Terminal will be reused by tasks, press any key to close it. 

All dependency looks good but still getting this gpiod lib not found for arm64.

Hey @vishalborle92,

Have you added the Debian packages to the torizonpackages.json file? We have a guide here for this here: Add Packages, Libraries, Tools and Files | Toradex Developer Center

-Eric

Hi @eric.tx

I was able to build my GPIO example the problem was in VS code settings.json not configured properly. But now when trying to run this example getting below ERROR:


Full log:

Container Runtime: docker
Run Arguments: -d -p 5002:5000 --restart=always registry:2
Container Name: registry
Container Exists
Container is running
 *  Terminal will be reused by tasks, press any key to close it. 

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

 *  Executing task: pwsh -nop .conf/validateDepsRunning.ps1 


⚠️ VALIDATING ENVIRONMENT


✅ Environment is valid!

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

 *  Executing task: bash -c [[ ! -z "192.168.209.40" ]] && true || false 

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

 *  Executing task: bash -c [[ "aarch64" == "aarch64" ]] && true || false 

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

 *  Executing task: sleep 1 

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

 *  Executing task: sshpass -p raj54321 scp -P 22 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /home/vishal/Toradex_Peripheral_Test/gpioC/docker-compose.yml torizon@192.168.209.40:~/ 

Warning: Permanently added '192.168.209.40' (ED25519) to the list of known hosts.
 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task: DOCKER_HOST=192.168.209.40:2375 docker image prune -f --filter=dangling=true 

Total reclaimed space: 0B
 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task: if [ false == false ]; then DOCKER_HOST=192.168.209.40:2375 docker compose -p torizon down --remove-orphans ; fi 

WARN[0000] Warning: No resource found to remove for project "torizon". 
 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task: DOCKER_HOST= docker build --pull -f /home/vishal/Toradex_Peripheral_Test/gpioC/Dockerfile.sdk /home/vishal/Toradex_Peripheral_Test/gpioC -t cross-toolchain-arm64-gpioc --build-arg IMAGE_ARCH=arm64 --build-arg GPU=-imx8 --build-arg APP_ROOT=/home/torizon/app 

[+] Building 3.2s (9/9) FINISHED                                                                                                                          docker:default
 => [internal] load build definition from Dockerfile.sdk                                                                                                            0.0s
 => => transferring dockerfile: 1.08kB                                                                                                                              0.0s
 => WARN: InvalidDefaultArgInFrom: Default value for ARG torizon/debian-cross-toolchain-${IMAGE_ARCH}:${CROSS_SDK_BASE_TAG} results in empty or invalid base image  0.0s
 => [internal] load metadata for docker.io/torizon/debian-cross-toolchain-arm64:3.3.0-bookworm                                                                      3.1s
 => [auth] torizon/debian-cross-toolchain-arm64:pull token for registry-1.docker.io                                                                                 0.0s
 => [internal] load .dockerignore                                                                                                                                   0.0s
 => => transferring context: 56B                                                                                                                                    0.0s
 => [1/4] FROM docker.io/torizon/debian-cross-toolchain-arm64:3.3.0-bookworm@sha256:46b730261b75685dd8bd454f295114bc1dfcd85f6e8f077b97bb57d719f033fd                0.0s
 => CACHED [2/4] RUN apt-get -q -y update &&     apt-get -q -y install     &&     apt-get clean && apt-get autoremove &&     rm -rf /var/lib/apt/lists/*            0.0s
 => CACHED [3/4] RUN apt-get -q -y update &&     apt-get -q -y install  libgpiod-dev:arm64     &&     apt-get clean && apt-get autoremove &&     rm -rf /var/lib/a  0.0s
 => CACHED [4/4] WORKDIR /home/torizon/app                                                                                                                          0.0s
 => exporting to image                                                                                                                                              0.0s
 => => exporting layers                                                                                                                                             0.0s
 => => writing image sha256:b8bfb7d61709dd80328fbaeb3512bdf8d08c52855c3924bab836ee7aeda213b1                                                                        0.0s
 => => naming to docker.io/library/cross-toolchain-arm64-gpioc                                                                                                      0.0s

 1 warning found (use docker --debug to expand):
 - InvalidDefaultArgInFrom: Default value for ARG torizon/debian-cross-toolchain-${IMAGE_ARCH}:${CROSS_SDK_BASE_TAG} results in empty or invalid base image name (line 16)
 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task: make ARCH=arm64 makedir 

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

 *  Executing task: DOCKER_HOST= docker run --rm -v /home/vishal/Toradex_Peripheral_Test/gpioC:/home/torizon/app cross-toolchain-arm64-gpioc make ARCH=arm64 CC=aarch64-linux-gnu-gcc debug 

make: Nothing to be done for 'debug'.
 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task: DOCKER_HOST= docker compose build --pull --build-arg SSHUSERNAME=torizon --build-arg APP_ROOT=/home/torizon/app --build-arg IMAGE_ARCH=arm64 --build-arg SSH_DEBUG_PORT=2230 --build-arg GPU=-imx8 gpioc-debug 

WARN[0000] The "DOCKER_LOGIN" variable is not set. Defaulting to a blank string. 
WARN[0000] /home/vishal/Toradex_Peripheral_Test/gpioC/docker-compose.yml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
[+] Building 3.2s (15/15) FINISHED                                                                                                                                       
 => [internal] load local bake definitions                                                                                                                          0.0s
 => => reading from stdin 629B                                                                                                                                      0.0s
 => [internal] load build definition from Dockerfile.debug                                                                                                          0.0s
 => => transferring dockerfile: 2.69kB                                                                                                                              0.0s
 => WARN: StageNameCasing: Stage name 'Debug' should be lowercase (line 34)                                                                                         0.0s
 => [internal] load metadata for docker.io/torizon/debian:3.3.0-bookworm                                                                                            3.0s
 => [auth] torizon/debian:pull token for registry-1.docker.io                                                                                                       0.0s
 => [internal] load .dockerignore                                                                                                                                   0.0s
 => => transferring context: 56B                                                                                                                                    0.0s
 => [1/7] FROM docker.io/torizon/debian:3.3.0-bookworm@sha256:0ce675b0a48960560e2add9299f60b025271caba22a371e05c1f28029b1f6b28                                      0.0s
 => [internal] load build context                                                                                                                                   0.0s
 => => transferring context: 219B                                                                                                                                   0.0s
 => CACHED [2/7] RUN apt-get -q -y update &&     apt-get -q -y install     openssl     openssh-server     rsync     file     curl     gdb &&     apt-get clean &&   0.0s
 => CACHED [3/7] RUN apt-get -q -y update &&     apt-get -q -y install  libgpiod-dev:arm64     &&     apt-get clean && apt-get autoremove &&     rm -rf /var/lib/a  0.0s
 => CACHED [4/7] COPY .conf/id_rsa.pub /id_rsa.pub                                                                                                                  0.0s
 => CACHED [5/7] RUN mkdir /var/run/sshd &&     sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g'         -i /etc/pam.d/sshd &&       0.0s
 => CACHED [6/7] RUN rm -r /etc/ssh/ssh*key &&     dpkg-reconfigure openssh-server                                                                                  0.0s
 => CACHED [7/7] COPY --chown=torizon:torizon ./build-arm64/debug /home/torizon/app                                                                                 0.0s
 => exporting to image                                                                                                                                              0.0s
 => => exporting layers                                                                                                                                             0.0s
 => => writing image sha256:0641a77627bc616bd845b4b9666f9636bc12973a6cb149602055ee0373584d8e                                                                        0.0s
 => => naming to localhost:5002/gpioc-debug:arm64                                                                                                                   0.0s
 => resolving provenance for metadata file                                                                                                                          0.0s
[+] Building 1/1
 ✔ gpioc-debug  Built                                                                                                                                               0.0s 
 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task: DOCKER_HOST= docker compose push gpioc-debug 

WARN[0000] The "DOCKER_LOGIN" variable is not set. Defaulting to a blank string. 
WARN[0000] /home/vishal/Toradex_Peripheral_Test/gpioC/docker-compose.yml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
[+] Pushing 17/17
 ✔ Pushing localhost:5002/gpioc-debug:arm64: ca8564d2dc49 Layer already exists                                                                                      0.0s 
 ✔ Pushing localhost:5002/gpioc-debug:arm64: 741b7819b2cb Layer already exists                                                                                      0.0s 
 ✔ Pushing localhost:5002/gpioc-debug:arm64: cb173e3ee503 Layer already exists                                                                                      0.0s 
 ✔ Pushing localhost:5002/gpioc-debug:arm64: 3dd5ff32f84e Layer already exists                                                                                      0.0s 
 ✔ Pushing localhost:5002/gpioc-debug:arm64: b937ad84fd14 Layer already exists                                                                                      0.0s 
 ✔ Pushing localhost:5002/gpioc-debug:arm64: a2e660bade7b Layer already exists                                                                                      0.0s 
 ✔ Pushing localhost:5002/gpioc-debug:arm64: b83567f86ab3 Layer already exists                                                                                      0.0s 
 ✔ Pushing localhost:5002/gpioc-debug:arm64: 011c6a76c6f1 Layer already exists                                                                                      0.0s 
 ✔ Pushing localhost:5002/gpioc-debug:arm64: 9a2f818ab1d2 Layer already exists                                                                                      0.0s 
 ✔ Pushing localhost:5002/gpioc-debug:arm64: 1534a4ee32df Layer already exists                                                                                      0.0s 
 ✔ Pushing localhost:5002/gpioc-debug:arm64: 6c6a5ec41a1a Layer already exists                                                                                      0.0s 
 ✔ Pushing localhost:5002/gpioc-debug:arm64: da5e0894d918 Layer already exists                                                                                      0.0s 
 ✔ Pushing localhost:5002/gpioc-debug:arm64: 1fbc9c24ec18 Layer already exists                                                                                      0.0s 
 ✔ Pushing localhost:5002/gpioc-debug:arm64: 451a08d8b887 Layer already exists                                                                                      0.0s 
 ✔ Pushing localhost:5002/gpioc-debug:arm64: 2bc4ea22b6d4 Layer already exists                                                                                      0.0s 
 ✔ Pushing localhost:5002/gpioc-debug:arm64: 08ee52a25812 Layer already exists                                                                                      0.0s 
 ✔ Pushing localhost:5002/gpioc-debug:arm64: 644fed2a3898 Layer already exists                                                                                      0.0s 
 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task: sshpass -p raj54321 ssh -p 22 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no torizon@192.168.209.40 LOCAL_REGISTRY=192.168.66.128 TAG=arm64 docker compose pull gpioc-debug 

Warning: Permanently added '192.168.209.40' (ED25519) to the list of known hosts.
time="2025-08-12T04:50:44Z" level=warning msg="The \"DOCKER_LOGIN\" variable is not set. Defaulting to a blank string."
time="2025-08-12T04:50:44Z" level=warning msg="/var/rootdirs/home/torizon/docker-compose.yml: `version` is obsolete"
 gpioc-debug Pulling 
 gpioc-debug Warning 
WARNING: Some service image(s) must be built from source by running:
    docker compose build gpioc-debug
1 error occurred:
        * Error response from daemon: Get "http://192.168.66.128:5002/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)



 *  The terminal process "sshpass '-p', 'raj54321', 'ssh', '-p', '22', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no', 'torizon@192.168.209.40', 'LOCAL_REGISTRY=192.168.66.128 TAG=arm64 docker compose pull gpioc-debug'" terminated with exit code: 18. 
 *  Terminal will be reused by tasks, press any key to close it. 

Could please help me out to solve this error to run simple GPIO example?

Thanks.

Hello @vishalborle92

@eric.tx is taking a well-deserved vacation and I’ve been asked to step in here. The way the IDE works is that your application is built as a container and stored in a docker registry running on your build system. This registry needs to be available from the device to be able to download the container images. If your device is unable to route to the laptop or you have a firewall blocking inbound connections, that will cause failures like this.

I’ve also seen some issues where a more complicated network setup on your build system would cause issues. More than 1 interface, for instance, or higher-end enterprise wifi protocols. Do you have anything like that?

From your Toradex module, can you ping the ip address of your build system? It seems that it is expected to be at 192.168.66.128.

Drew

Hello @drew.tx

I checked ping 192.168.66.128 and getting response as below:

More than 1 interface, for instance, or higher-end enterprise wifi protocols. Do you have anything like that? - More than 1 interface we connected only one carrier board.

Thanks,
Vishal

Hi Vishal,

Apologies for not being more clear. My question about enterprise wifi, multiple interfaces, etc was related to your desktop setup. We have seen many instances where IT setups would interfere with the connectivity between the IDE extension and the target hardware. In some cases users need to setup an isolated lab network without their IT additions to be able to get full functionality.

I can’t say with certainty that is your issue here but the net result is that your board is trying to contact the container registry running on your desktop and is failing. I know we are implementing some changes to remove the need for that container registry; I don’t believe that feature is available yet but I think it will help in this case.

First step though, can you switch to the prerelease version of the Torizon Marketplace extension? In the VSCode Extension Marketplace tab, if you search for “Torizon” and display the page for our extension, there should be a button to switch to prerelease. Screenshot attached.

Please let me know how the prelease goes and any more details about your IT environment that may be relevant.

Thanks,
Drew

Hi Vishal,

I just heard back from the devs that the new feature I mentioned is actually in the prerelease version, so it may well solve your connection issue. Please let me know how it goes.

Drew