Openwrt-libtool using the wrong linker

I’m trying to port a library called Unibilium to OpenWrt as one of the dependencies of Neovim. The source MakeFile calls libtoolfor compiling and linking. Here’s the excerpt:

uniutil.lo: uniutil.c unibilium.h
	$(LIBTOOL) --mode=compile --tag=CC $(CC) -I. -DTERMINFO_DIRS='$(TERMINFO_DIRS)' -Wall -std=c99 $(CFLAGS) $(CFLAGS_DEBUG) -o $@ -c $<

$(LIBRARY): $(OBJECTS)
	$(LIBTOOL) --mode=link --tag=CC $(CC) $(LDFLAGS) -rpath '$(LIBDIR)' -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) -o $@ $^

I verified that it’s the libtoolfrom staging_dir/host/bin/libtool that’s being called, not the system one, and it works for the compiling part, but not for linking.

libtool --mode=link --tag=CC aarch64-openwrt-linux-musl-gcc -L/home/vkosikhin/git/openwrt/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.3.0_musl/usr/lib -L/home/vkosikhin/git/openwrt/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.3.0_musl/lib -fuse-ld=bfd -znow -zrelro  -rpath '/usr/local/lib' -version-info 4:0:0 -o libunibilium.la unibilium.lo uninames.lo uniutil.lo

OpenWrt-libtool: link: /home/vkosikhin/git/openwrt/staging_dir/host/bin/gcc -std=gnu23 -shared  -fPIC -DPIC  .libs/unibilium.o .libs/uninames.o .libs/uniutil.o   -L/home/vkosikhin/git/openwrt/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.3.0_musl/usr/lib -L/home/vkosikhin/git/openwrt/staging_dir/toolchain-aarch64_cortex-a53_gcc-14.3.0_musl/lib  -fuse-ld=bfd   -Wl,-soname -Wl,libunibilium.so.4 -o .libs/libunibilium.so.4.0.0
/usr/bin/ld.bfd: .libs/unibilium.o: Relocations in generic ELF (EM: 183)
/usr/bin/ld.bfd: .libs/unibilium.o: Relocations in generic ELF (EM: 183)
/usr/bin/ld.bfd: .libs/unibilium.o: error adding symbols: file in wrong format
collect2: error: ld returned 1 exit status

I separated the log lines for clarity. As shown, the CCvariable still expands to aarch64-openwrt-linux-musl-gcc, but OpenWrt-libtoolis completely ignoring it in favor of the system cc. Why does this happen while linking specifically and not while compiling?

How would we guess what you stuffed in package makefile?

I omitted the package MakeFile because I’m not overriding any sections or variables yet. The InstallDev and …/install sections are a placeholder.

include $(TOPDIR)/rules.mk

PKG_NAME:=unibilium
PKG_VERSION:=2.0.0
PKG_RELEASE:=1

PKG_SOURCE_PROTO:=git
PKG_SOURCE_VERSION:=v$(PKG_VERSION)
PKG_SOURCE_URL:=https://github.com/mauke/unibilium.git
PKG_MIRROR_HASH:=9e6202d3a6ad5b977ed0ea7e037fd819fd8834d5b61f5353351ef0a1377b4bc5

PKG_MAINTAINER:=
PKG_LICENSE:=LGPL-3.0-or-later
PKG_LICENSE_FILES:=LICENSE

PKG_BUILD_PARALLEL:=1
PKG_INSTALL:=1

include $(INCLUDE_DIR)/package.mk

define Package/libunibilium
  SECTION:=libs
  CATEGORY:=Libraries
  TITLE:=Terminfo parsing library
  URL:=https://github.com/mauke/unibilium/
endef

define Package/libunibilium/description
  Unibilium is a very basic terminfo library which can read and write
  ncurses-style terminfo files interpret terminfo format strings.
endef

define Build/InstallDev
	$(INSTALL_DIR) $(1)/usr/include/tree_sitter
	$(INSTALL_DIR) $(1)/usr/lib/pkgconfig
	$(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/local/include/tree_sitter/api.h $(1)/usr/include/tree_sitter/
	$(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/local/lib/pkgconfig/tree-sitter.pc $(1)/usr/lib/pkgconfig/
	$(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/local/lib/libtree-sitter.a $(1)/usr/lib/
	$(CP) $(PKG_INSTALL_DIR)/usr/local/lib/libtree-sitter.so* $(1)/usr/lib/
endef

define Package/libunibilium/install
	$(INSTALL_DIR) $(1)/usr/lib
	$(CP) $(PKG_INSTALL_DIR)/usr/local/lib/libtree-sitter.so* $(1)/usr/lib/
endef

$(eval $(call BuildPackage,libunibilium))


Patch out rpath statement.

3 Likes

Thank you, that did the trick.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.