Menu ▾ ▴

#315 Android NDK cross build requires extra configure steps

2.0
open
nobody
None
2024-04-19
2024-04-19
No

I do this for Android:

I cross compile on Arch Linux:

`
export API=32
export TOOLCHAIN=/opt/android-ndk/toolchains/llvm/prebuilt/linux-x86_64

export AR=$TOOLCHAIN/bin/llvm-ar
export CC=$TOOLCHAIN/bin/$TARGET$API-clang
export AS=$CC
export CXX=$TOOLCHAIN/bin/$TARGET$API-clang++
export LD=$TOOLCHAIN/bin/ld
export RANLIB=$TOOLCHAIN/bin/llvm-ranlib
export STRIP=$TOOLCHAIN/bin/llvm-strip

export CFLAGS=-fPIE
export LDFLAGS="-pie -static-libstdc++"
`

Android NDK CLANG's default behavior, as specified in that URL I sent to their docs, is to NOT statically link the C++ library, but then you must also deploy the shared library file with your Iperf2 binary for it to find it.

I build Iperf2 using NDK CLANG, so I need to statically link the C++ library, to avoid having to copy around that libc++.so file.

But if building Iperf2 for Android using an older NDK, or GCC somehow, since the GCC built C++ shared libraries are already found on the Android file system, this would also work, avoiding the need for that flag. (I assume this is how prebuilt Iperf3 binaries available through Google search have been built, based on what ldd told me, they were using the GCC C++ system shared library file.)

Then I do this:

bash configure \ --enable-af-packet=no \ --enable-tuntap-tun=no \ --enable-tuntap-tap=no \ --host=aarch64-linux-android

Build throws multiple errors in Listener.cpp unless I explicitly disabled those features.

That could be a ticketable item as well I suppose, if you wanted to avoid passing flags, and Android build still compile.

Discussion


Log in to post a comment.