Pkg-Config is a popular tool used with autoconf to figure out what libraries are available for a target, as well as how to include/link against them. pkg-config
reads the .pc
files found in the lib/pkgconfig/
folder. .pc
files look something like this:
prefix=/usr/local
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib
Name: foo
Description: The foo library
Version: 1.0.0
Cflags: -I${includedir}/foo
Libs: -L${libdir} -lfoo
A standard wrapper recommended here: https://autotools.io/pkgconfig/cross-compiling.html
#!/bin/sh
SYSROOT=/build/root
export PKG_CONFIG_DIR=
export PKG_CONFIG_LIBDIR=${SYSROOT}/usr/lib/pkgconfig:${SYSROOT}/usr/share/pkgconfig
export PKG_CONFIG_SYSROOT_DIR=${SYSROOT}
exec pkg-config "$@"
Notably PKG_CONFIG_LIBDIR
needed to be set before it actually worked for me (otherwise it kept finding the stuff in my linux install).
I mistakenly thought you’d have to install pkg-config in to each toolchain, but I was wrong. You just need a smart script.
I combined a bunch of information I read in to a single script passes the correct settings to libSDL’s configure script to make it target different platforms.
#!/bin/sh
TARGET=arm-linux-androideabi
#TARGET=aarch64-linux-android
#TARGET=i686-linux-android
#TARGET=x86_64-linux-android
ROOT=~/android/ndk-arm
#ROOT=~/android/ndk-arm64
#ROOT=~/android/ndk-x86
#ROOT=~/android/ndk-x86_64
SYSROOT=${ROOT}/sysroot
TOOL_PREFIX=${ROOT}/bin/
INSTALL_PREFIX=${SYSROOT}/usr/local/
export CC="${TOOL_PREFIX}clang"
export AR="${TOOL_PREFIX}llvm-ar"
export LD="${TOOL_PREFIX}${TARGET}-ld"
export PKG_CONFIG_DIR=
export PKG_CONFIG_LIBDIR=${SYSROOT}/usr/lib/pkgconfig:${SYSROOT}/usr/share/pkgconfig
export PKG_CONFIG_SYSROOT_DIR=${SYSROOT}
../SDL/configure --host=$TARGET --prefix=$INSTALL_PREFIX --with-sysroot=$SYSROOT --disable-shared
Above is a script I wrote for building and installing SDL in to the various standalone toolchains generated by the Android SDK. It tells pkg-config
to use the specific sysroot, which should be empty (no libraries available). Without the pkg-config
stuff above, the system will try to use dependencies found in your system’s sysroot (i.e. /
).
References: https://wiki.libsdl.org/Android, https://people.freedesktop.org/~dbn/pkg-config-guide.html#writing