如何使用 libpcap 库为 OpenWRT 交叉编译 C 程序?

How to cross-compile a C program for OpenWRT with libpcap library?

我有一小段使用 libpacp 库的代码:

ifacelookup.c

#include <stdio.h>
#include <pcap.h>

int main(int argc, char *argv[])
{
    char *dev, errbuf[PCAP_ERRBUF_SIZE];

    dev = pcap_lookupdev(errbuf);
    if (dev == NULL) {
        fprintf(stderr, "Couldn't find default device: %s\n", errbuf);
        return(2);
    }
    printf("Device: %s\n", dev);
    return(0);
}

makefile 为:

LIBS=-lpcap 
ifacelookup: ifacelookup.o
    $(CC) opensniff.o -o ifacelookup $(LDFLAGS) $(LIBS)
ifacelookupf.o: ifacelookup.c
    $(CC) $(CFLAGS) -c ifacelookup.c
clean:
    rm *.o ifacelookup

我在OpenWrt SDK上编译了它并成功构建了一个.ipk包。它的 Makefile 是

include $(TOPDIR)/rules.mk

PKG_NAME:=ifacelookup
PKG_VERSION:=1.0.1
PKG_MAINTAINER:=MDK 
PKG_LICENSE:=GPL-2
PKG_BUILD_DEPENDS:=libpcap    # Added the dependancy 

include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/kernel.mk

PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)

define Package/ifacelookup
    SECTION:=utils
    CATEGORY:=Utilities
    DEPENDS:=+libpcap    # Added the dependent library
    TITLE:=Test raditap header fields.
endef

define Package/$(PKG_NAME)/description
    Test the network card for the radiotap fields it supports.
endef

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

define Build/Configure
endef

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

define Package/$(PKG_NAME)/install
    $(INSTALL_DIR) $(1)/bin
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/$(PKG_NAME) $(1)/bin
endef

$(eval $(call BuildPackage,$(PKG_NAME)))

当尝试使用

在 OpenWrt 设备上安装此包时
 opkg install /tmp/ifacelookup_1.0.1_ar71xx.ipk  // transfered .ipk to /tmp folder using scp

我收到此错误消息:

Installing ifacelookup (1.0.1) to root...
Collected errors:
 * satisfy_dependencies_for: Cannot satisfy the following dependencies for ifacelookup:
 *  libpcap * 
 * opkg_install_cmd: Cannot install package ifacelookup.

出了什么问题?

我成功了。要在 OpenWrt 上制作此程序 运行,libpcap 应该安装在设备

opkg update
opkg install libpcap