Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Has anyone come across a Fortran 77 emulator or compiler for iOS devices?

share|improve this question
Why would you want one? – Fake Name Feb 16 '12 at 6:14

Perhaps it's best done with a pre-compiler translating Fortran to C (and integrate that into Xcode as a separate build step). One such tool is e.g.

Maybe one can also have a look at the gnu fortran compiler, as far as I remember it also started out as a precompiler translating Fortran to C.

share|improve this answer

It can be accomplished using the Dragonegg plugin for GCC (frontend), a generic LLVM installation (backend), and the Apple linker. I have been able to successfully build and run a 64-bit Fortran application on iOS 8.1 built on Mac OS X 10.10 using GCC 4.8 and LLVM 3.5. The process is not very straightforward and requires a number of hacks and some scripting, but the high-level steps are:

  1. Install GCC 4.8 from HPC for Mac OS X into /usr/local
  2. Install Clang/LLVM 3.5 from into /usr/local
  3. Download the Dragonegg source code from the LLVM website
  4. Build and install it to /usr/local/lib/gcc/x86_64-apple-darwin12.5.0/4.8.1/plugin
  5. Download GCC 4.8.1 sources
  6. Build libgfortran for arm64 using a combination of Apple clang for C/C++, Dragonegg for Fortran, and some wrapper scripts to piece together the compilers
  7. Install libgfortran.dylib and libgfortran.3.dylib to /Applications/
  8. Install libgfortran.3.dylib on the iPhone under /usr/local/lib

Now if you got this far, compile a Fortran source file into an iOS binary using:

  1. gfortran -O3 -fplugin=dragonegg -fplugin-arg-dragonegg-llvm-codegen-optimize=3 -fplugin-arg-dragonegg-emit-ir -S -o main.s main.f
  2. llc -mtriple arm64-apple-darwin -filetype=obj -o main.o main.s
  3. ld -arch arm64 -syslibroot /Applications/ -lSystem -lgfortran main.o -o main

Precompiled binaries for Dragonegg and libgfortran can be found here:

UPDATE: The precompiled binaries archive now contains fat libraries (armv7s, arm64) and some bug fixes to the wrapper scripts.

share|improve this answer
I found this link useful for building,… – Eric Nov 21 '14 at 9:45
FYI, I was able to compile all of the Fortran benchmarks from SPEC FP for iOS using this method. – Eric Nov 29 '14 at 10:31
Could you be more specific with your 6th step, build libgfortran for arm64? I'm trying to find a way to built it but I did not succeed. – Alessandra Siqueira da Silva P Feb 24 '15 at 16:05
I had to get this work done quickly so I didn't take notes, but I didn't want to lose the binaries. I just remember I had to hack the source quite a bit. The majority of the trouble was setting the fortran compiler to my wrapper script since gfortran has some fortran libraries inside. – Eric Feb 25 '15 at 18:33
Thank you very much for the idea. It works. Regarding the 8th step, I was not able to copy the dylib into the proposed location. I had to change the location like this: install_name_tool -id @executable_path/../Frameworks/libgfortran.3.dylib libgfortran.3.dylib. In XCode a Copy build step is needed. Copy libgfortran.3.dylib and set the destination to Executables. – timomeinen Jan 23 at 16:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.