Cross compile libpcap for Android/arm

Compile libpcap 1.5.2
export ANDROID_NDK=/home/ducalpha/android/ndk # or your Android NDK root directory
export CC=${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
export CCOPT="-O2 -fpic --sysroot=/home/ducalpha/adr/ndk/platforms/android-14/arch-arm -DANDROID -DOS_ANDROID"
export CFLAGS="--sysroot=${ANDROID_NDK}/platforms/android-14/arch-arm -DANDROID -DOS_ANDROID"
export LDFLAGS="--sysroot=${ANDROID_NDK}/platforms/android-14/arch-arm -fPIC -mandroid -L${ANDROID_NDK}/platforms/android-14/arch-arm/usr/lib"
./configure --host=arm-linux --with-pcap=linux --prefix=${ANDROID_NDK}/platforms/android-14/arch-arm/usr
make
make install

Compile libpcap 1.4.0
Reason for my failure: libpcap 1.4.0 has a "wrong" configure script and creates "wrong" config.h so we need to fix them
1. configure script: remove all #define in configure
     why? this will make android ndk gcc fail to compile because of multiple definition of int8, int16, int32, u_int8, u_int16, u_int32
2. Create correct config.h 
Manually fix #define in config.h :(

After the above step, we must:
1. export CFLAGS and LDLAGS for Android
2. use prefix for installation
  --prefix=/home/ducalpha/adr/ndk/platforms/android-14/arch-arm/usr/lib
     /usr/lib: library *.so files
     /usr/include: include files

All commands needed for compilation:
Change directory to the root directory of libpcap
export ANDROID_NDK=/home/ducalpha/android/ndk
export CC=${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
export CCOPT="-O2 -fpic --sysroot=/home/ducalpha/adr/ndk/platforms/android-14/arch-arm -DANDROID -DOS_ANDROID"
export CFLAGS="--sysroot=${ANDROID_NDK}/platforms/android-14/arch-arm -DANDROID -DOS_ANDROID"
export LDFLAGS="--sysroot=${ANDROID_NDK}/platforms/android-14/arch-arm -fPIC -mandroid -L${ANDROID_NDK}/platforms/android-14/arch-arm/usr/lib"
./configure --host=arm-linux --with-pcap=linux --prefix=${ANDROID_NDK}/platforms/android-14/arch-arm/usr
make
make install

Comments

  1. Thanks, this worked. But I used the latest libpcap from their github page. Their normal ...1.7.4.tar.gz release will cause a "cannot find ifbond" error with the ndk.

    ReplyDelete
    Replies
    1. You need to check the source code or Makefile to see what caused the error. Another way is to use an older version of libpcap.

      Delete

Post a Comment

Popular posts from this blog

Cross-compile dropbear/dbclient ssh for arm/Android

cross compile git for arm/Android