Search code examples
android-ndkautoconf

NDK Toolchain documentation faulty for 'Autoconf' projects (for example libxml2)


Using Google NDK toolchain with NDK21 for 'autoconf' projects says this:

# Check out the source.
git clone https://github.com/glennrp/libpng -b v1.6.37
cd libpng
# Only choose one of these, depending on your build machine...
export TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/darwin-x86_64
export TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64
# Only choose one of these, depending on your device...
export TARGET=aarch64-linux-android
export TARGET=armv7a-linux-androideabi
export TARGET=i686-linux-android
export TARGET=x86_64-linux-android
# Set this to your minSdkVersion.
export API=21
# Configure and build.
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
./configure --host $TARGET
make

It seems that this example cannot be used for other 'autoconf' projects like 'libxml2'. Using the lines above will break build process when trying to create a shared library.

'libtool' does not create a 'so' file in this case but only creates a 'la' file.

The reason for that is that the line

export LD=$TOOLCHAIN/bin/ld

is pointed to a non existing file. Because of that libtool does not invoke the linking process. If I change the line to

export LD=$TOOLCHAIN/bin/ld.lld

or do not export 'LD' at all it is working fine.

See the same problem here https://github.com/libexpat/libexpat/issues/312

Question

Is the Google NDK documentation really wrong here or do I miss something?


Solution

  • The docs also say

    The tools selected in this sample are correct for NDK r22 and newer. Older NDKs may require different tools.

    You're using r21.

    I just followed the instructions using r24 and the only issue I ran into was https://github.com/glennrp/libpng/issues/347, which is a libpng issue, not an Android issue. Replacing that #ifdef __clang__ with #if defined(__clang__) && defined(__APPLE__) makes the project compile just fine.