How to build i686-linux-android-gfortran for android-ndk8b (x86 arch Android)? How to build i686-linux-android-gfortran for android-ndk8b (x86 arch Android)? android android

How to build i686-linux-android-gfortran for android-ndk8b (x86 arch Android)?


From https://groups.google.com/forum/#!msg/android-ndk/QR1qiN0jIpE/g0MHkhTd4YMJ as selalerer suggested. I didn't try this, so I'm posting as a community wiki for reference purposes.

Fortran for x86 Android =================

The guide is based on this one, many thanks to Phil: Compiling Android NDK with Objective-C-enabled gcc errors

1) Download and unpack Android NDK 'android-ndk-r8c', (the older -r8b NDK won't work due to missing link.h!): wget http://dl.google.com/android/ndk/android-ndk-r8c-linux-x86.tar.bz2

2) Create somewhere a folder called 'toolchain-src' (e.g. inside the folder android-ndk-r8c), 'cd' to this new folder

3) Make sure to have git installed ('yum install git' or whatever..) and download the toolchain sources:

  git clone https://android.googlesource.com/toolchain/build.git  git clone https://android.googlesource.com/toolchain/gmp.git  git clone https://android.googlesource.com/toolchain/gdb.git  git clone https://android.googlesource.com/toolchain/mpc.git  git clone https://android.googlesource.com/toolchain/mpfr.git  git clone https://android.googlesource.com/toolchain/expat.git

4) Create the folder 'binutils', 'cd' to this directory, unpack binutils-2.23 there: wget ftp.gnu.org/gnu/binutils/binutils-2.23.tar.gz tar -xvzf binutils-2.23.tar.gz You should now have a folder toolchain-src/binutils/binutils-2.23

5) Change to folder toolchain-src/build, edit the Makefile.in, changing the line: --with-gnu-as --with-gnu-ld --enable-languages=c,c++ to --with-gnu-as --with-gnu-ld --enable-languages=c,c++,fortran

6) In the file android-ndk-r8c/build/tools/build-mingw64-toolchain.sh change the line: var_append GCC_CONFIGURE_OPTIONS "--enable-languages=c,c++" to var_append GCC_CONFIGURE_OPTIONS "--enable-languages=c,c++,fortran"

7) In the file android-ndk-r8c/build/tools/build-gcc.sh, change the line: EXTRA_CONFIG_FLAGS=$EXTRA_CONFIG_FLAGS" --disable-libquadmath --disable-plugin" to EXTRA_CONFIG_FLAGS=$EXTRA_CONFIG_FLAGS" --disable-libquadmath --disable-libquadmath-support --disable-plugin"

8) In the file android-ndk-r8c/build/tools/build-host-gcc.sh, change the line: ARGS=$ARGS" --enable-languages=c,c++" to ARGS=$ARGS" --enable-languages=c,c++,fortran" And change the line ARGS=$ARGS" --disable-libquadmath --disable-plugin --disable-libitm --disable-bootstrap" to ARGS=$ARGS" --disable-libquadmath --disable-libquadmath-support --disable-plugin --disable-libitm --disable-bootstrap"

9) Build your new toolchain: /your/path/to/android-ndk-r8c/build/tools/build-gcc.sh -j1 --gmp-version=5.0.5 --mpfr-version=2.4.2 --mpc-version=0.8.1 --binutils-version=2.23 --gdb-version=7.3.x /your/path/to/toolchain-src /your/path/to/android-ndk-r8c x86-4.7 (don't worry about messages like 'expr: warning: unportable BRE:')

10) And go down to your knees in front of the screen, praying to the Lord that somehow these countless configure scripts doing checks that nobody needs, using an ugly shell language that cooks your brain with indentation going from right to left, will somehow manage to compile a zillion of far too small files (so that 10% of the time is spent on compilation and 90% on starting up GCC), and after an hour of watching progress with tail -F /tmp/ndk-YourUserName/build/toolchain/config.log your toolchain will be magically ready. You'll find it in the android-ndk-r8c/toolchains folder.

11) Finally, 'cd' to the folder '/your/path/to/android-ndk-r8c/toolchains/x86-4.7/prebuilt/linux-x86/i686-linux-android' and run this command: ln -s ../libexec libexec Without this command, it may happen that g++ raises the error message "g++: fatal error: -fuse-linker-plugin, but liblto_plugin.so not found". Using strace, I found that g++ looks in the wrong folder, but the link above lets it find the file liblto_plugin.so nevertheless.

And here are a few lessons learned on the way, so that Google finds this page:

*) To speed up the compilation, you can remove the '-j1'. But only after you got it to work once, since building in parallel on multiple CPU cores was reported to cause additional troubles.

*) The error message "Link tests are not allowed after GCC_NO_EXECUTABLES" shows up when linking fails for x86 (works for ARM). The reason is that GCC does not include the proper ANDROID_STARTFILE_SPEC and ANDROID_ENDFILE_SPEC from gcc-4.6.1/gcc/config/linux-android.h. GCC 4.6.1 only specifies them for ARM, but not for i386, GCC 4.8.0 however does. The GCCs downloaded from Google also do, so best use Google's GCC.

*) The error message "fatal error: link.h: No such file or directory" also happens with Google's GCC, and apparently (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50877) only when you enable additional languages like objc or fortran. The bug thread is here: http://gcc.gnu.org/ml/gcc-bugs/2012-08/msg00494.html MIPS has link.h in android-ndk-r8b/platforms/android-9/arch-mips/usr/include In android-ndk-r8c, link.h is now also present in android-9/arch-x86/usr/include/link.h, so this bug was fixed.

*) The error message "fatal error: quadmath_weak.h: No such file or directory": It also happens with the latest gcc-4.8, so we can just continue using Googles GCC 4.7. Google itself uses --disable-libquadmath, but we additionally need --disable-libquadmathsupport (see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47648). So this needs to be added in android-ndk-r8c/build/tools/build-gcc.sh and android-ndk-r8c/build/tools/build-host-gcc.sh

*) The error message "error: Pthreads are required to build libatomic" Happens when building the ARM version of gcc-4.8 downloaded from gnu.org, better stay with Google's GCCs.

*) The GCC that came with android-ndk-r8c didn't work for me (error message about libstdc++.so.6 being too old), while the one in android-ndk-r8b worked without problems. Since the android-ndk should support as many environments as possible, I'm not sure why the Googlers decided to depend on a newer libstdc++, but the good news are that building your own toolchain solves the issue.

*) If you get an error while compiling generic-morestack.c, then replace #ifdef linux // On Linux, the first two real time signals are used by the NPTL with #if defined(GLIBC) && defined(linux) // On Linux, the first two real time signals are used by the NPTL