问题
Trying to compile a basic program which uses pcap.h. I've set up the environment on my Mac OSX box which uses the iPhone 3.1.3 SDK for an iPhone 3GS. I've also installed libpcap to ~/libpcap so I can tell gcc where to look for the headers using the -I flag. However, it fails with an ld warning saying the file is not of the required architecture.
I'm compiling with the following line:
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -I /Users/abnev/libpcap/include -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.3.sdk -o pcap pcap.c -lpcap
Error's being generated are:
ld: warning: in /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.3.sdk/usr/lib/libpcap.dylib, file is not of required architecture
Undefined symbols:
"_pcap_geterr", referenced from:
_main in ccOL3e0B.o
_main in ccOL3e0B.o
"_pcap_open_live", referenced from:
_main in ccOL3e0B.o
"_pcap_next", referenced from:
_main in ccOL3e0B.o
"_pcap_lookupdev", referenced from:
_main in ccOL3e0B.o
"_pcap_setfilter", referenced from:
_main in ccOL3e0B.o
"_pcap_lookupnet", referenced from:
_main in ccOL3e0B.o
"_pcap_close", referenced from:
_main in ccOL3e0B.o
"_pcap_compile", referenced from:
_main in ccOL3e0B.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
I assume now that I need to recompile libpcap for the armv6 architecture (iPhone) but checking the ./configure options doesn't help. I've attempted to Google around for this but there is very little out there.
回答1:
pcap.c
isn't the source to libpcap, it's one of the source files to libpcap. You'd have to compile all the source files and build them into a library.
Doing
CFLAGS="-I /Users/abnev/libpcap/include -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.3.sdk" ./configure
might produce a Makefile that would cross-compile libpcap for iOS.
I presume you will be installing libpcap, or the application built using it, on a jailbroken iPhone, at least if you're going to be capturing packets, because you would need root access in order for libpcap to be able to open a BPF device in order to be able to capture.
来源:https://stackoverflow.com/questions/3071034/can-libpcap-be-compiled-for-iphone-armv6