【问题标题】:libpcap static linking errors compiling with ndk toolchains for android使用适用于 android 的 ndk 工具链编译的 libpcap 静态链接错误
【发布时间】:2011-07-24 01:52:01
【问题描述】:

我已经使用 Git 从 android 源代码下载了外部文件夹中的 libpcap 和 回购。我使用 ndk (android-ndk-r5b) 的工具包来编译这些库 步骤:

./configure --prefix=path-to-android-src/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin 打扫干净 制作 进行安装

然后生成一个文件 libpcap.a。

我使用 libpcap (sniffer.c) 制作了一个简单的嗅探器。当我尝试编译它时,会出现以下错误: agcc sniffer.c libpcap.a

sniffer.c:9:18: error: pcap.h: No such file or directory
sniffer.c:19: warning: 'struct pcap_pkthdr' declared inside parameter list
sniffer.c:19: warning: its scope is only this definition or declaration, which is      probably not what you want
sniffer.c: In function 'processPacket':
sniffer.c:23: warning: incompatible implicit declaration of built-in function 'printf'
sniffer.c:24: error: dereferencing pointer to incomplete type
sniffer.c:26: error: dereferencing pointer to incomplete type
sniffer.c:33: error: dereferencing pointer to incomplete type
sniffer.c: In function 'main':
sniffer.c:45: error: 'pcap_t' undeclared (first use in this function)
sniffer.c:45: error: (Each undeclared identifier is reported only once
sniffer.c:45: error: for each function it appears in.)
sniffer.c:45: error: 'descr' undeclared (first use in this function)
sniffer.c:46: error: 'PCAP_ERRBUF_SIZE' undeclared (first use in this function)
sniffer.c:62: warning: incompatible implicit declaration of built-in function 'printf'
sniffer.c:66: warning: incompatible implicit declaration of built-in function 'fprintf'
sniffer.c:66: error: 'stderr' undeclared (first use in this function)
sniffer.c:72: warning: incompatible implicit declaration of built-in function 'fprintf'

当我尝试提前生成目标代码时: agcc -c 嗅探器.o 嗅探器.c 发生了同样的错误。

谁能解释一下如何解决这个问题?

这是我在 bashrc 文件中使用的 agcc 的别名: ./configure --prefix=/home/petsas/projects/mobile-attacks/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/

另外,我附上了一个包含上述命令输出的文件:configure、make 和 make install。

(我将错误放在代码样式中,因为存在对齐错误)

提前谢谢你!

-- 更新--

我使用选项 -I 和 -L 来指定包含和库文件,现在这些错误都消失了..

这是我的新错误日志:

agcc --static -I /home/petsas/projects/mobile-attacks/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/include -L /home/petsas/projects/mobile-attacks/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/lib -o sniffer sniffer.c libpcap.a

/home/petsas/projects/mobile-attacks/android-ndk-r5b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld: libpcap.a(pcap-linux.o): Relocations in generic ELF (EM: 3)
/home/petsas/projects/mobile-attacks/android-ndk-r5b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld: libpcap.a(pcap-linux.o): Relocations in generic ELF (EM: 3)
/home/petsas/projects/mobile-attacks/android-ndk-r5b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld: libpcap.a(pcap-linux.o): Relocations in generic ELF (EM: 3)
libpcap.a: could not read symbols: File in wrong format
collect2: ld returned 1 exit status

有什么想法吗?

【问题讨论】:

    标签: android android-ndk cross-compiling static-linking libpcap


    【解决方案1】:

    标题

    按照我上面描述的方式我找不到解决方案,但我成功了 编写一个 Android.mdk 文件并使用 android NDK 的 ndk-build。

    我将 libpcap 目录放入 android-ndk-r5b/samples 中,我对 Android.mdk 进行了一些修改 和目录的结构,以便看起来像样本目录中的其他目录和 我在 android-ndk-r5b 目录中使用了 ndk-build 命令:

    ndk-build -C 示例/android-ndk-r5b

    一切正常!我能够生成一个 libpicap.so 文件,并使用 命令:

                     in android (phone):
                     $ su
                     # mount -o,rw remount /dev/block/mtdblock4 /system/lib
    
                     in my Desktop:
                     $ adb push libpcap.so /system/lib/
    

    我做了一个简单的嗅探器,我编译并与 libpcap.so 链接,并且在 我的HTC英雄! ;)

    【讨论】:

    • 你是如何与 libpcap.so 链接的?
    • 我必须检查我参与的一个旧项目才能回答你。我想我已经更改了项目的 Android.mk 文件以生成动态库文件(libpicap.so),然后我用这个库交叉编译了我的嗅探器。
    猜你喜欢
    • 1970-01-01
    • 2011-07-24
    • 1970-01-01
    • 1970-01-01
    • 2014-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多