Search code examples
capiembedded-linuxgpiodynamic-library

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!


Solution

  • 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.