Fortunately I managed to compile the gcc Fortran cross-compiler with the help of Mike Long's blog. As an added bonus, I managed to build gfortran 4.8.0 not only for the ARM but also for the x86 toolchain, as well as update the script to the latest Android NDK (currently r8d).
What you need to do is the following:
- download the fortran4android shell script.
- download the ndk-r8d fortran patch.
- run the script in your directory:
$ fortran4android - wait, wait, wait, ... and you will see in the android-ndk-r8d/toolchains directory two new toolchains called arm-linux-androideabi-4.8.0 and x86-4.8.0
- Enjoy your new gfortran compiler.
Note that I've successfully tested the script only on Ubuntu 12.04.
Addendum of August 30, 2013
I now have available a patch for the newer android-ndk-r9. To use this instead of the patch above:- download the ndk-r9-fortran-patch
- change the fortran4android script by replacing "r8d" with "r9" everywhere
- run the fortran4android script in your directory.
Thanks for the script, works great!
ReplyDeleteI'm curious if you know why gcc builds --without-quadmath for ARM. I'm trying to compile the R project, but it seems R is reliant on libquadmath.
Joshua,
DeleteI'm sure we can tweak the gcc configure to build with quadmath support. In alternative you can checkout this post http://rwiki.sciviews.org/doku.php?id=getting-started:installation:android where they seems to have ported R to Android and there is also a link to download a gcc toolchain to install on the device itself.
It's possible that in the future I will experiment myself with porting R to Android, and if so I will post on this blog. Stay tuned.
Great work! It really makes me happy to see the amount of interest there is in giving Fortran a chance to shine on new platforms. Any chance you've managed to get OpenMP support enabled for ARM on Android? I've been putting off doing that for a while, so... ;)
ReplyDeleteNo, thank you for your initial hard work! Regarding OpenMP I don't have any porting plans for Android (for now).
DeleteMaybe MPI would be a better alternative? Or even better, Coarray fortran! :D
DeleteExcellent. Thank-you for this. I work in an industry that relies heavily on models written in Fortran. What you have done opens a lot of doors.
ReplyDeleteHi, i am an engineer working in offshore oil/gas field.. i am good with fortran 95 and have many self written programs written in f95 for my work related calculations.. i was searching for option to make them work on my android phone and a link from google directed me here.. any one could please suggest how/whether it is possible to make use of my fortran skills for andorid app development.. thanks
DeleteHi,
ReplyDeleteI have tried running the script and got the following error message:
/bin/ksh: Defective interpreter: File or directory not found
I am running Kubuntu 13.04. Could that be the reason, and any idea how to fix it?
Thanks
You can either try to install the Korn shell (ksh) package on your system or in alternative you can change the script and make it bash compatible (the only changes should be convert the first line from !#/bin/ksh to !#/bin/bash and see what happens).
DeleteEditing the first line to !#/bin/bash worked like a charm. Thank you very much :-)
DeleteHi,
ReplyDeleteThanks for writing this report.
I tried this on Ubuntu 14.04 and it builds gcc and g++ but not gfortran. Any idea?
What kind of error are you getting? I tried right now and it fails in the config step complaining that the m4 library is missing. Try to install m4 (a macro processing language) from the Ubuntu Software Center and run the script from scratch. I'll try the same and let you know if I bump into other problems.
DeleteHi ,
ReplyDeleteThank you for posting this, I am able to generate toolchain for 32 bit please let me know what changes should i perform to generate toolchain for 64 bit platform.
Regards,
Vineet Pant
Vineet,
DeleteI never tried to generate the toolchain for a 64 bit platform, and off the bat I don't know what kind of modifications to the script is necessary to do that. Just for clarification what are you trying to accomplish, generate a 64-bit executable to run on Android?
Hi Danilo,
DeleteYou are right, I am trying to generate 64 bit android executable.
Hi Danilo ,
ReplyDeleteI am facing some errors due to missing header files , please let me know if there is some particular way to resolve it.
test.cpp:1:20: fatal error: iostream: No such file or directory
#include
Regards,
Vineet Pant
Hi, Danilo.
ReplyDeleteThank for the best guide for fortran addition to arm-android toolchain.
Unfortunately i have problem with getting google build directory
> wget https://dl.dropbox.com/u/97874334/build_tools_ndk_r6b.tgz
Building with latest from google repo really breaks things, as you mentitioned in comment in your script.
I think we can modify script with checking out to certain revision from git repo, just i need to understand what is really goes wrong there.
Regards, Victor.
Victor,
Deleteit's been a while since I was playing around with the Fortran compiler. As you mentioned, you could try to get the code from the official Google repo but dated back in February 2013.
Hi, i am an engineer working in offshore oil/gas field.. i am good with fortran 95 and have many self written programs written in f95 for my work related calculations.. i was searching for option to make them work on my android phone and a link from google directed me here.. any one could please suggest how/whether it is possible to make use of my fortran skills for andorid app development.. thanks
ReplyDeleteGreat post. Could you recommend how to crosscompile fortran for the Pandaboad (Omap ARM)?
ReplyDeleteDave,
DeleteI have access to a Panda board but I never had the chance/time to play with cross-compiling Fortran. Sorry.
This comment has been removed by the author.
ReplyDeleteHi there Danilo,
ReplyDeleteI'm having a bit of trouble building fortran4android in Ubuntu 12.04 and I wondered if you could give me a little help?
I've run your build exactly as shown on http://danilogiulianelli.blogspot.co.uk/2013/02/how-to-build-gcc-fortran-cross-compiler.html .
After installing ksh, and invoking the fortran4android command, all the build tools appear to be downloaded successfully (ndk, binutils, gdb, gmp, mpc, mpfr).
In the build I get this with several modules:
ERROR: Missing gdb sources: /home/ubuntuuser/Downloads/android-ndk-r8d/src/gdb/gdb-7.3.x
Obviously I have tried correcting the versions, but then I get:
Error while trying to configure toolchain build. See /tmp/ndk-ubuntuuser/build/toolchain/config.log
I'd appreciate it if you could possibly retry the build and/or possibly advise me as to what I'm doing wrong?
Greg,
Deletenot sure what's going on in your case. My suggestion is try to look at the log files to see if you spot something obvious. Perhaps a mismatch with the required gdb version used by the script.
This comment has been removed by the author.
ReplyDeleteThanks a lot for the post!
ReplyDeleteI was able to get through to building of toolchain but im getting errors after that. could you please advice on what I should do
Thanks!
Sysroot : Copying: /home/mukta/and/android-ndk-r8d/platforms/android-9/arch-x86 --> /tmp/ndk-root/build/toolchain/prefix/sysroot
Configure: x86-4.8.0 toolchain build
Building : x86-4.8.0 toolchain [this can take a long time].
Error while building toolchain. See /tmp/ndk-root/build/toolchain/config.log
Mukta,
Deletesorry but without you posting any specific errors from the listed log file, I cannot guess what could have possibly gone wrong.
Hi,
DeleteI have copied a section of the log file where the first error pops up. I am not sure how to correct this.
if [ xinfo = xinfo ]; then \
rm -f doc/gfortran.info-*; \
makeinfo --split-size=5000000 --split-size=5000000 -I /home/mukta/cross/and/android-ndk-r8d/src/build/../gcc/gcc-4.8.0/gcc/doc/include -I /home/mukta/cross/and/android-ndk-r8d/src/build/../gcc/gcc-4.8.0/gcc/fortran \
-o doc/gfortran.info /home/mukta/cross/and/android-ndk-r8d/src/build/../gcc/gcc-4.8.0/gcc/fortran/gfortran.texi; \
else true; fi
/home/mukta/cross/and/android-ndk-r8d/src/build/../gcc/gcc-4.8.0/gcc/doc/cppopts.texi:808: @itemx must follow @item
Makefile:4292: recipe for target 'doc/cpp.info' failed
make[3]: *** [doc/cpp.info] Error 1
make[3]: *** Waiting for unfinished jobs....
how pass " -mfloat-abi=softfp -mfpu=vfp" to the compiler
ReplyDelete/home/pcl/android-ndk-r9/toolchains/arm-linux-androideabi-4.8.0/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gfortran. Since LOCAL_CFLAGS is not working.
try to install a fresh setup of this, sadly, it is not working now.
ReplyDeletehttps://dl.dropbox.com/u/97874334/build_tools_ndk_r6b.tgz seems not there. There seems some bugs in the gfortan compilers as described by
https://gcc.gnu.org/ml/fortran/2014-03/msg00125.html.
The problem of fortran for me is:
gcc-4.8.0/libgfortran/io/unix.c:1817: error: undefined reference to 'ttyname_r' when i try to link openblas with gfortran