2

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

./configure --prefix=path-to-android-src/mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin make clean make make install

然后生成一个文件 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 sniffer.o sniffer.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

有任何想法吗?

4

1 回答 1

2

标题

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

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

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 Hero 中完美运行!;)

于 2011-03-30T14:07:54.417 回答