Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

libgpiod API usage (Linux shared libraries)

Does anyone have any experience with the libgpiod API? I have installed it on my linux platform but am unable to call its library functions.

I installed by:

git clone git://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git
cd libgpiod
./autogen.sh
make
make install

Afterwards, I see the libgpiod.so library in /usr/local/lib/ and gpiod.h in /usr/local/include/ (for good measure I ran ldconfig as well). However, when I try to compile the following:

test.c

#include <gpiod.h>

struct gpio_chip *chip;    

int main(void)
{
    chip = gpio_chip_open("/dev/gpiochip4");
    return 0;
}

I get the following error: undefined reference to 'gpiod_chip_open'

Can anyone help me see where I am going wrong?

Many thanks in advance!

like image 647
Bastinoboy Avatar asked Sep 01 '25 10:09

Bastinoboy


2 Answers

You missed the library for linking with -l flag.

Compile it like this:

gcc -lgpiod test.c

In addition, you might need to configure the runtime paths also for the SO file if it's a custom one. See this thread for more details on runtime shared object locations.

like image 74
Azeem Avatar answered Sep 03 '25 02:09

Azeem


Please try this command:

Install library first:

sudo apt-get install -y libgpiod-dev

Compile command:

gcc GPIO_LED.c -o led_read_status -lgpiod

Run as root user.

In addition you can use gpio tool for debugging GPIO:

  1. gpiodetect
  2. gpioinfo
  3. gpioset
  4. gpioget
like image 41
Vikas Dwivedi Avatar answered Sep 03 '25 03:09

Vikas Dwivedi