lukassz lukassz - 22 days ago 9
Linux Question

Android NDK cannot cross compile SQLite - crtend_so.o: No such file or directory

I'm trying to cross compile sqlite sources for android platform.
This is my config for env

export NDK=/home/lukassz/android-ndk

export NDK_ROOT=/home/lukassz/android-ndk
export PATH=$NDK_ROOT/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin:$PATH
export CC=arm-linux-androideabi-gcc
export LD=arm-linux-androideabi-ld
export CPPFLAGS=-I$NDK_ROOT/platforms/android-18/arch-arm/usr/include
export CFLAGS="-nostdlib" LDFLAGS="-Wl,-rpath-link=$NDK_ROOT/platforms/android-18/arch-arm/usr/lib/ -L$NDK_ROOT/platforms/android-18/arch-arm/usr/lib"
export LIBS="-lc"

export CPP=arm-linux-androideabi-cpp
export CC=arm-linux-androideabi-gcc
export CXX=arm-linux-androideabi-g++
export LD=arm-linux-androideabi-ld
export AS=arm-linux-androideabi-as
export AR=arm-linux-androideabi-ar
export RANLIB=arm-linux-androideabi-ranlib


export ANDROID_SYSROOT=$NDK_ROOT/platforms/android-18/arch-arm
export CPPFLAGS="--sysroot=$ANDROID_SYSROOT"
export CFLAGS="--sysroot=$ANDROID_SYSROOT"
export CXXFLAGS="--sysroot=$ANDROID_SYSROOT"


Next I make
./configure
with

./configure --host=arm-linux-androideabi CC=arm-linux-androideabi-gcc LD=arm-linux-androideabi-ld CPPFLAGS="-I$NDK_ROOT/platforms/android-18/arch-arm/usr/include" CFLAGS="-nostdlib" LDFLAGS="-Wl,-rpath-link=$NDK_ROOT/platforms/android-18/arch-arm/usr/lib/ -L$NDK_ROOT/platforms/android-18/arch-arm/usr/lib" LIBS="-lc"


No errors, but when I type
make
I gets

libtool: link: arm-linux-androideabi-gcc -shared -fPIC -DPIC .libs/sqlite3.o -L/home/lukassz/android-ndk/platforms/android-18/arch-arm/usr/lib -ldl -lc -Wl,-rpath-link=/home/lukassz/android-ndk/platforms/android-18/arch-arm/usr/lib/ -Wl,-soname -Wl,libsqlite3.so -o .libs/libsqlite3.so
/home/lukassz/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot open crtbegin_so.o: No such file or directory
/home/lukassz/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot open crtend_so.o: No such file or directory
collect2: error: ld returned 1 exit status
Makefile:456: recipe for target 'libsqlite3.la' failed
make: *** [libsqlite3.la] Error 1


Where is the problem?

Answer

Linker can not find startup binaries since you give no path to sysroot. Linker's command line must contain --sysroot=/path/to/android/sysroot too. Then, -L option should be used only for third party library paths, not for system ones, so you should get rid of it. Also -lc is completely redundant since normal binaries are linked against libc by default.

You may pass --sysroot via LDFLAGS, exactly like you've done with CFLAGS at compilation step. But it is a bit ugly. Try to read ./configure --help carefully. There surely should be clear way how to pass path to sysroot instead of hacking with *FLAGS variables.