Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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

2 Answers 2

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. http://www.greatmigrations.com/tools_gmFortran.aspx

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. http://gcc.gnu.org/fortran/

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 llvm.org into /usr/local
  3. Download the Dragonegg source code from the LLVM website
  4. Build dragonegg.so 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/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/usr/lib
  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/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk -lSystem -lgfortran main.o -o main

Precompiled binaries for Dragonegg and libgfortran can be found here: http://download.zeroepoch.com/gfortran-ios/gfortran-ios.tar.bz2

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 dragonegg.so, stackoverflow.com/questions/26009274/… –  Eric Nov 21 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 at 10:31

Your Answer

 
discard

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.