After reading this thread I decided to give libgpiod another go on Trixie.
I downloaded one example https://git.kernel.org/pub/scm/libs/lib ... c?h=v2.2.x
I installed sudo apt install libgpiod-dev
Attempting to compile resulted in the followingOthers claim to have had success; can anyone explain why my attempt failed, or more importantly tell me what magic incantations I need to get this to compile (and then link).
( I have had some success running python gpiod code.)
For clarity this is the code I downloaded:-
I downloaded one example https://git.kernel.org/pub/scm/libs/lib ... c?h=v2.2.x
I installed sudo apt install libgpiod-dev
Attempting to compile resulted in the following
Code:
gcc toggle_line_value.c /usr/bin/ld: /tmp/ccmiiMny.o: in function `main':toggle_line_value.c:(.text+0x18): undefined reference to `gpiod_chip_open'/usr/bin/ld: toggle_line_value.c:(.text+0x74): undefined reference to `gpiod_chip_get_line_info'/usr/bin/ld: toggle_line_value.c:(.text+0xc0): undefined reference to `gpiod_line_info_get_name'/usr/bin/ld: toggle_line_value.c:(.text+0xe4): undefined reference to `gpiod_line_info_get_consumer'/usr/bin/ld: toggle_line_value.c:(.text+0x108): undefined reference to `gpiod_line_info_get_direction'/usr/bin/ld: toggle_line_value.c:(.text+0x130): undefined reference to `gpiod_line_info_get_offset'/usr/bin/ld: toggle_line_value.c:(.text+0x13c): undefined reference to `gpiod_line_info_is_active_low'/usr/bin/ld: toggle_line_value.c:(.text+0x188): undefined reference to `gpiod_line_info_free'/usr/bin/ld: toggle_line_value.c:(.text+0x190): undefined reference to `gpiod_chip_close'collect2: error: ld returned 1 exit status( I have had some success running python gpiod code.)
For clarity this is the code I downloaded:-
Code:
// SPDX-License-Identifier: GPL-2.0-or-later// SPDX-FileCopyrightText: 2023 Kent Gibson <warthog618@gmail.com>/* Minimal example of reading the info for a line. */#include <errno.h>#include <gpiod.h>#include <stdio.h>#include <stdlib.h>#include <string.h>int main(void){/* Example configuration - customize to suit your situation. */static const char *const chip_path = "/dev/gpiochip0";static const unsigned int line_offset = 3;const char *name, *consumer, *dir;struct gpiod_line_info *info;struct gpiod_chip *chip;chip = gpiod_chip_open(chip_path);if (!chip) {fprintf(stderr, "failed to open chip: %s\n", strerror(errno));return EXIT_FAILURE;}info = gpiod_chip_get_line_info(chip, line_offset);if (!info) {fprintf(stderr, "failed to read info: %s\n", strerror(errno));return EXIT_FAILURE;}name = gpiod_line_info_get_name(info);if (!name)name = "unnamed";consumer = gpiod_line_info_get_consumer(info);if (!consumer)consumer = "unused";dir = (gpiod_line_info_get_direction(info) == GPIOD_LINE_DIRECTION_INPUT) ? "input" : "output";printf("line %3d: %12s %12s %8s %10s\n", gpiod_line_info_get_offset(info), name, consumer, dir, gpiod_line_info_is_active_low(info) ? "active-low" : "active-high");gpiod_line_info_free(info);gpiod_chip_close(chip);return EXIT_SUCCESS;}Statistics: Posted by Milliways — Fri Dec 05, 2025 2:53 am