我正在尝试在Android nexus-7 wifi平板电脑上运行packetspammer应用程序(代号:grouper)。我下载了libpcap库,并能够生成静态库(libpcap.a)。但是,当我尝试使用NDK-build构建packetspammer应用程序时,我不断收到链接器错误。
我的文件夹结构如下所示:
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程序员指南,并按照&#34; Building / Standalone工具链&#34;部分进行了操作。以及&#34; Building / Android.mk&#34;。即使使用独立工具链,我也会遇到相同的链接器错误。
在我被困在这里之前,我发现很多帖子帮我解决了几个错误。以下是这些链接:
undefined reference error while statically linking;
trouble linking static libraries;
using a pre-compiled static library;
答案 0 :(得分:2)
我能够解决这个问题。我按照this SO question (compile libpcap using android ndk)中接受的答案,从this site下载了libpcap。
我编译并构建了libpcap.a静态库,将其链接到packetspammer android.mk文件并获得最终的可执行文件。