我已经使用 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
有任何想法吗?