Eclipse not finding SDK library

Hello everyone,

I’m having some trouble running a simple GPIO example using the libgpiod library.

After setting up Eclipse following this tutorial I tried to build the demo code. However, I’m getting the error undefined reference to the libgpiod functions.

My sample code:

#include <stdbool.h>
#include <stdio.h>
#include <gpiod.h>

int main(void) {
	struct gpiod_chip *output_chip;
	struct gpiod_line *output_line;

	//	Configure a GPIO as output:

	/* open the GPIO bank */
	output_chip = gpiod_chip_open_by_number(1);

	/* open the GPIO line */
	output_line = gpiod_chip_get_line(output_chip, 1);

	/* config as output and set a description */
	gpiod_line_request_output(output_line, "gpio-test",GPIOD_LINE_ACTIVE_STATE_HIGH);

	//	Toggle a GPIO:

	while (1) {
		/* Clear */
		int line_value = 0;
		gpiod_line_set_value(output_line, line_value);

		/* Set */
		line_value = 1;
		gpiod_line_set_value(output_line, line_value);
	}

	return 0;
}

What I’ve tried and verified so far:

  • I’m setting up the SDK environment and then starting eclipse on the same terminal window
  • Eclipse can find the #include <gpiod.h>
  • I can find the gpiod.h on the project’s includes folder

Hi @farina!

Which SDK are you using for this project?

Your SDK has got to have the libgpiod includes so the linker can find the references to these functions.

You may have to build a new SDK using OpenEmbedded.

Hello @gustavo.tx

I am using the SDK generated by bitbake for my custom image.

I can find the libgpiod includes on my SDK, but just to make sure, this are all gpio related files on my SDK folder:

./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/lib/.debug/libgpiod.so.2.1.0
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/lib/libgpiod.so
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/lib/libgpiod.so.2
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/lib/pkgconfig/libgpiod.pc
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/lib/libgpiod.so.2.1.0
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/src/debug/ofono/1.24-r0/ofono-1.24/plugins/nokia-gpio.c
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/src/debug/ofono/1.24-r0/ofono-1.24/plugins/nokia-gpio.h
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/src/debug/libsoc/0.8.2-r0/git/lib/gpio.c
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/src/debug/libsoc/0.8.2-r0/git/lib/include/libsoc_gpio.h
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/src/debug/libgpiod
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/src/debug/libgpiod/1.2-r0/libgpiod-1.2
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/src/debug/libgpiod/1.2-r0/libgpiod-1.2/src/tools/gpioinfo.c
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/src/debug/libgpiod/1.2-r0/libgpiod-1.2/src/tools/gpiomon.c
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/src/debug/libgpiod/1.2-r0/libgpiod-1.2/src/tools/gpioget.c
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/src/debug/libgpiod/1.2-r0/libgpiod-1.2/src/tools/gpiofind.c
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/src/debug/libgpiod/1.2-r0/libgpiod-1.2/src/tools/gpioset.c
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/src/debug/libgpiod/1.2-r0/libgpiod-1.2/src/tools/gpiodetect.c
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/src/debug/libgpiod/1.2-r0/libgpiod-1.2/include/gpiod.h
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/bin/gpioinfo
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/bin/gpioset
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/bin/.debug/gpioinfo
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/bin/.debug/gpioset
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/bin/.debug/gpiofind
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/bin/.debug/gpioget
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/bin/.debug/gpiomon
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/bin/.debug/gpiodetect
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/bin/gpiofind
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/bin/gpioget
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/bin/gpiomon
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/bin/gpiodetect
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/include/libsoc_gpio.h
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/include/gpiod.h
./sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/include/linux/gpio.h

Also, I checked the image recipes with this command:

bitbake -g console-tdx-image && cat pn-depends.dot | grep -v -e '-native' | grep -v digraph | grep -v -e '-image' | awk '{print $1}' | sort | uniq

And the libgpiod shows up on the list.

Hi @farina!

Your SDK looks fine. This looks like some issue with Eclipse and its configuration.

I’ll give this a try and let you know if I can reproduce it.

Great,

I used this tutorial to configure Eclipse.

Also, you can download my SDK here

Just an update,

I’m also having the same problem with the pthread library

Hi

Did you tell the linker that you want to link libgpiod and pthreads?

I.e. did you add (in addition to ${LDFLAGS}) -lgpiod -lpthread to the linker flags. Please refer to step 15 of the tutorial.

Max

@farina,

As my colleague @max.tx mentioned, you have to add the flags for the libraries you’re trying to use on the linker call.
If you’re following the tutorial, on step 15 we use the ${LDFLAGS} environment variable. Add -lgpiod and -pthread so it’ll be like ${LDFLAGS} -lgpiod -lpthread.

Hello Max,

No I didn’t and this solved my problem!

Thank you

Mauricio

Hi Mauricio

What error did you get? Maybe it’s the missing l in the answer above, which I corrected now.