【问题标题】:libpcap static linking errors (undefined reference to pcap APIs) in Android NDK-buildAndroid NDK-build 中的 libpcap 静态链接错误(未定义对 pcap API 的引用)
【发布时间】:2014-09-25 20:56:03
【问题描述】:

我正在尝试在 Android nexus-7 wifi only 平板电脑(代号:grouper)上运行 packetspammer 应用程序。我下载了libpcap 库并能够生成静态库(libpcap.a)。但是,当我尝试使用 NDK-build 构建 packetpammer 应用程序时,我不断收到链接器错误。

我的文件夹结构如下:

packetspammer
|
jni
  |
  packetspammer source files
  Android.mk file that links in libpcap and builds the packetspammer binary
  <Directory>platform_external_libpcap 
       |
       libpcap.a file

这是我的 android.mk 文件:

#Links the libpcap library
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := platform_external_libpcap/libpcap
LOCAL_SRC_FILES := platform_external_libpcap/libpcap.a
LOCAL_EXPORT_C_INCLUDES := platform_external_libpcap
include $(PREBUILT_STATIC_LIBRARY)

#Builds packetspammer app
include $(call all-subdir-makefiles)
include $(CLEAR_VARS)

LOCAL_MODULE    := packetspammer
LOCAL_SRC_FILES := radiotap.c packetspammer.c 
LOCAL_STATIC_LIBRARIES  := platform_external_libpcap/libpcap.a
LOCAL_C_INCLUDES := ~/android/android-ndk-r10b/platforms/android-L/arch-arm/usr/include \
                ~/packetspammer/jni/platform_external_libpcap

TARGET_ARCH     := arm

include $(BUILD_SHARED_LIBRARY)

这些是我收到的错误消息:

error: undefined reference to 'pcap_open_live'
error: undefined reference to 'pcap_datalink'
error: undefined reference to 'pcap_compile'
error: undefined reference to 'pcap_geterr'
error: undefined reference to 'pcap_setfilter'
error: undefined reference to 'pcap_geterr'
error: undefined reference to 'pcap_freecode'
error: undefined reference to 'pcap_setnonblock'
error: undefined reference to 'pcap_next_ex'
error: undefined reference to 'pcap_inject'

您能告诉我 Android.mk 文件或我遵循的流程有什么问题吗?我查看了 NDK 程序员指南并遵循“构建/独立工具链”以及“构建/Android.mk”部分。即使使用独立工具链,我也会遇到相同的链接器错误。

在我陷入困境之前,我发现了许多帮助我解决了几个错误的帖子。以下是这些链接:

undefined reference error while statically linking;

linking third party libs;

trouble linking static libraries;

using a pre-compiled static library;

libpcap for android;

compile libpcap using android ndk

porting JNetPcap

【问题讨论】:

  • 也许你的 libpcap.a 缺少一些应该覆盖 undef 字段的头文件?

标签: android android-ndk static-linking libpcap android.mk


【解决方案1】:

我能够解决这个问题。我遵循this SO question (compile libpcap using android ndk) 中接受的答案并从this site 下载了libpcap。

我编译并构建了 libpcap.a 静态库,将其链接到 packetpammer android.mk 文件中并获得了最终的可执行文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-24
    • 1970-01-01
    • 2012-03-02
    • 2011-07-24
    • 1970-01-01
    • 2016-11-11
    • 2019-01-16
    • 2013-05-07
    相关资源
    最近更新 更多