Linker error in simple cpde, can't find any reason

I have a binary that I am trying to use with. I installed libgpiod via openwrt menuconfig.

The compiler sees the gpiod.h file fine, and the linker appears to find the -lgpiod (as changing it results in an error). I verified that the function being called (gpiod_chip_open) is present is inside

My objects are before my libs. I'm not confusing cpp and c, or 32 and 64. I have no idea why I can't do this linkage. Trying other gpiod functions is the same problem.

I found larger in staging_dir/target-mipsel_24kc_uClibc/usr/lib, and copied it to my filesystem /usr/lib, and the linking worked.
Why is the version that openwrt put into the filesystem smaller, and why wouldn't it link?

original error:

/kernel/staging_dir/toolchain-mipsel_24kc_gcc-7.3.0_uClibc/bin/mipsel-openwrt-linux-gcc -Wall -O2 -o renesascom renesascom_uart.o renesascom_gpio.o renesascom_telegraph.o renesascom_ipc.o renesascom_llist.o renesascom_scheduling.o renesascom_threads.o renesascom.o -Lrootfs/usr/lib -pthread -lgpiod
renesascom_gpio.o: In function `mt7620_gpio_dev_open':
renesascom_gpio.c:(.text+0xb8): undefined reference to `gpiod_chip_open'

Binaries are stripped before being packaged for release. The one in staging_dir may have sections contents like debuginfo etc. That's the main cause of size difference I guess.

As for why the one in rootfs/usr/lib was rejected by the linker, I guess it's because the binary was stripped of section headers by sstrip. To verify, try sstrip staging_dir/xxx and see if the error can be reproduced. sstrip should be available at staging_dir/host/bin

I think the project in inherited has a flawed make system. Instead of doing -L towards the file system from the rootfs.tgz, I think I am supposed to do -L to either somewhere in staging_dir or build_dir. The rootfs is optimized for space, and the linker cant follow the shared library references.

If anyone has a template makefile for making custom binaries against openwrt toolchain/libs, please share.

The build system is geared to look for libraries in staging_dir. This is by design.

You can use the following command to find packages whose source code are maintained with the OpenWrt package Makefile.

find package/ -type d -name src

Hmmm, surprising.

Which version of OpenWrt are you using and from where?

18.0.6 branch, unfortunately stuck using uClibc for now as I have to use some libs that were made against it and dont have source code for.

1 Like

Hey, even I am facing this issue in Buildroot. Can anyone tell me what's the fix?