Re: how to build i686-linux-android-gfortran for android-ndk8b (x86 arch Android) ??

982 views
Skip to first unread message

mikelong

unread,
Aug 23, 2012, 5:17:17 PM8/23/12
to andro...@googlegroups.com
For what it's worth, I tried building the x86 toolchain with gfortran today using the build environment set up with the new script from my site and it did not work.  It doesn't give the error that you saw, so maybe that's a good sign.  Here is what I get in the build log:

configure:1393: error: Unsupported target i686-pc-linux-android.

I don't have any x86 Android devices, so my motivation is low to do anything more with this right now, but maybe the above error will make the fix obvious to someone else here. (fingers crossed)

Mike
specificimpulses.blogspot.com



On Friday, August 17, 2012 7:01:23 PM UTC-5, gunda wrote:

I tried building i686-linux-android-gfortran using build-gcc.sh following this (its for androdindk-7b ) but i get error about link.h, i added link.h from here gives further more errors . Has anyone tried enabling i686-linux-android-gfortran for x86 Android

Thank you

mikelong

unread,
Jan 2, 2013, 7:25:11 PM1/2/13
to andro...@googlegroups.com
Wow.. that is an impressive bit of hacking!  Reading your summary gave me flashbacks to the horrors I went through getting Fortran to work with r6b.  I've been putting off moving from r8b to r8c because I didn't see anything interesting to me in the release notes and r8b is working well for what I'm doing right now.  That brings up a question though.. Have you found a better way to get the ndk-build command to work with Fortran sources?  That is one of the reasons I published the installer script, since it makes a number of ugly hacks on the build scripts to allow building Native Activity based applications with mixed C and Fortran sources.

Having that working 'out of the box' would be ideal.  That, and enabling OpenMP for parallel coding.

Thanks for sharing your work!

Mike

On Friday, December 21, 2012 6:06:27 PM UTC-6, Elmar wrote:


On Saturday, August 18, 2012 2:01:23 AM UTC+2, gunda wrote:

I tried building i686-linux-android-gfortran using build-gcc.sh following this (its for androdindk-7b ) but i get error about link.h, i added link.h from here gives further more errors . Has anyone tried enabling i686-linux-android-gfortran for x86 Android


Well, I now spent an entire week on this nasty topic (fortunately I could do something else while it was compiling ;-), and got it working. Here are the details:

   Fortran for x86 Android
   =================
 
   The guide is based on this one, many thanks to Phil:
   http://stackoverflow.com/questions/13072751/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
  

steve kirby

unread,
Dec 12, 2013, 7:36:46 PM12/12/13
to andro...@googlegroups.com
I concur with what Mike Long said earlier - this is excellent and impressive work.  Thanks very much for posting it.  I am anxious to get gfortran going on my android (simulator at this point).  I have hit a glitch with your recipe and maybe you can clue me in.  First let me note what I've had to do differently as I try to get gfortran going using android-ndk-r9b.
 
1. added these to the list you already had -
  since I was getting errors in the config.log indicating that these packages were missing.
 
I edited all of the files you mentioned appropriately, to add fortran compilation, to c and c++, and to set certain flags.
 
Then I make the call to build-gcc.sh as follows:

/home/skirby/android-ndk-r9b/build/tools/build-gcc.sh -j1 --gmp-version=5.0.5 --mpfr-version=2.4.2 --mpc-versioin=1.0.1 --binutils-version=2.24 --gdb-versoin=7.6 /home/skirby/android-ndk-r9b/toolchain-src /home/skirby/android-ndk-r9b x86-4.8

And my config.log file (see 2 lines below) is indicating that it doesn't have an appropriate C compiler (even though I have (I guess GNU) GCC 4.8.2 installed) --

"checking compiler gcc -m32 -O2 -s -Wno-error ... no"

"configure error: could not find a working compiler"

And the config.log file indicates that the gcc compiler didn't understand the flags given it:

configure:4171: WARNING: unrecognized options: --enable-initfini-array, --disable-nls, --disable-libquadmath, ...

What I'm wondering is that in your writeup you recommend using "Google's GCC" to avoid certain error messages?  How is Google GCC different from GNU GCC?

Is "Google GCC" the one from the call "git clone https://android.googlesource.com/toolchain/gcc.git" which I already did?  And then I need to compile the gcc source that this pulls down and use this as my resident GCC for the gfortran build?

Thanks for any clues here --

Best regards,

Steve

    

Reply all
Reply to author
Forward
0 new messages