Search code examples
androidc++compiler-constructiontoolchainandroid-ndk

Android Building Toolchain can't find/missing STL header directory


I've build the Android NDK toolchain manually. Everything works except when I use the compiler it can't find basic STL stuff like . So it can't compile code containing STL because it doesn't know where to look for the headers by default. I've never had this problem before using a custom or prebuilt toolchain. However if I manually add the include directories like

 -I$(NDK_TOOLCHAIN)/arm-linux-androideabi/include/c++/4.6/

Then it works just fine. It is a pain to add every important dir manually (there is more than this one). Surely something broken in the process.

These are the steps I followed to get it build:

 sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl

 Download NDK

 Untar NDK to [SOME_LOCATION], using /opt/ndk/

 Set NDK_ROOT=/opt/ndk/

  ./build/tools/download-toolchain-sources.sh src/

 Download MPC 0.9

 Move mpc tar to ./src/mpc/

 ./build/tools/build-gcc.sh --gmp-version=4.3.2 --mpc-version=0.9 --mpfr-version=2.4.2 --binutils-version=2.21 $(pwd)/src $(pwd) arm-linux-androideabi-4.6

 ./build/tools/build-gcc.sh --gmp-version=4.3.2 --mpc-version=0.9 --mpfr-version=2.4.2 --binutils-version=2.21 $(pwd)/src $(pwd) x86-4.6

 ./build/tools/build-gcc.sh --gmp-version=4.3.2 --mpc-version=0.9 --mpfr-version=2.4.2 --binutils-version=2.21 $(pwd)/src $(pwd) mipsel-linux-android-4.6

All the STL files exist in the proper location. All the headers and compiled libraries for each version if I build a STANDALONE toolchain after using as reference these custom built toolchains.

== UPDATE

Forcing gcc to spit out its include search paths:

  echo "#include <bogus.h> int main(){}" > t.c; /opt/android-9_arm/bin/arm-linux-androideabi-gcc -v t.c; rm t.c

This contains a search path under includes:

 /opt/android-9_arm/bin/../lib/gcc/arm-linux-androideabi/4.6.x-google/../../../../arm-linux-androideabi/include

At that location is indeed the following ./cxx/4.6/STL_HEADERS

Comparing the output with a NDK build from google does indeed differ in serious spots. The real question is now how do I guarantee my custom build of GCC points to the appropriate G++ STL header location.


Solution

  • It turned out to be a bug in make-standalone-toolchain.sh. The fix was:

    mv $NDK_TOOLCHAIN/arm-linux-androideabi/include/c++/4.6 $NDK_TOOLCHAIN/arm-linux-androideabi/include/c++/4.6.x-google
    

    That fixed it for the most part. However now that the ndkr8b has released with official GCC 4.6 support this bug stills exists (as of july 25 2012). More details on some bugs related to the standalone toolchain (http://code.google.com/p/android/issues/detail?id=35279).