1

I'm trying to write an OpenWRT package that uses a dynamically linked library that I cross-compile too. As far as I can tell compiling the library into a .so file works fine. After compiling find . -name "libname.so" inside the root directory returns the following:

./staging_dir/target-mips_34kc_uClibc-0.9.33.2/root-ar71xx/usr/lib/libname.so
./staging_dir/target-mips_34kc_uClibc-0.9.33.2/usr/lib/libname.so
./build_dir/target-mips_34kc_uClibc-0.9.33.2/libname-1.0/ipkg-ar71xx/libname/usr/lib/libname.so
./build_dir/target-mips_34kc_uClibc-0.9.33.2/libname-1.0/libname.so
./build_dir/target-mips_34kc_uClibc-0.9.33.2/root-ar71xx/usr/lib/libname.so

How exactly do I use this to link the library to my project? In my projects Makefile I have:

include $(TOPDIR)/rules.mk

PKG_NAME:=blocker
PKG_VERSION:=1
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)

include $(INCLUDE_DIR)/package.mk

define Package/blocker
    TITLE:=$(PKG_NAME)
    SECTION:=util
    CATEGORY:=Utilities
    DEPENDS:=+libname
endef

TARGET_CFLAGS += -Wall -llibname

define Package/blocker/description
    Blocks incomming SSH and HTTP connections
endef

define Build/Prepare
    mkdir -p $(PKG_BUILD_DIR)
    $(CP) ./src/* $(PKG_BUILD_DIR)/
endef

define Build/Compile
    $(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) \
    $(TARGET_CONFIGURE_OPTS)
endef

define Package/blocker/install
    $(INSTALL_DIR) $(1)/sbin/
    $(INSTALL_DIR) $(1)/etc/config
    $(INSTALL_DIR) $(1)/etc/init.d
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/files/blocker.init $(1)/etc/init.d/blocker
    $(INSTALL_DATA) $(PKG_BUILD_DIR)/files/blocker.conf $(1)/etc/config/blocker
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/blocker $(1)/sbin/blocker
endef

$(eval $(call BuildPackage,blocker))

However, compiling this package throws an error:

#include <libname.h> // <-- fatal error: libname.h: No such file or directory

int main(void)
{
    return 1;
}
  • 1
    Header files are not the same thing as libraries - I'm not familiar with that Makefile syntax, but you will probably need to modify the TARGET_CFLAGS to add an include file search path of the form -I path/to/dir where dir is the containing directory for libname.h. (As an aside, TARGET_CFLAGS may not be the appropriate place for -llibname either - I would have expected that to belong in a LDFLAGS type variable.) – steeldriver Jul 21 '17 at 16:21
-1

After compiling libname librarry in installation block install the libname.h file in ?(1)/usr/lib, so that when you compile your package it can locate the header.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.