6
votes

I need to compile Fortran-77 subroutines to be accessible on iOS. I am using GCC with the DragonEgg plugin, so I can use gfortran with the LLVM backend. I followed this answer but I am stuck when it comes to build libgfortran for armv7, armv7s and arm64.

  • Can I build libgfortran alone or is it always necessary to compile the GCC suite completely?
  • What is the correct way of producing this library for a different target? Is it possible to use GCC for this step or do I need LLVM for the arm*-targets?

Building GCC with arm-targets using GCC I get these errors:

./configure --prefix=/tmp/out --host=arm-apple-darwin --enable-languages=fortran
make
…
make[2]: arm-apple-darwin-ar: No such file or directory
make[2]: *** [libiberty.a] Error 1
make[1]: *** [all-libiberty] Error 2

Building GCC with arm-targets using LLVM I have problems with configure:

export CC="$(xcrun -sdk iphoneos -find clang)"
export CPP="$CC -E"
export CFLAGS="-arch armv7 -arch armv7s -arch arm64 -isysroot $(xcrun --sdk iphoneos --show-sdk-path) -miphoneos-version-min=9.2"
export AR=$(xcrun -sdk iphoneos -find ar)
export RANLIB=$(xcrun -sdk iphoneos -find ranlib)
export CPPFLAGS="-arch armv7 -arch armv7s -arch arm64 -isysroot $(xcrun --sdk iphoneos --show-sdk-path) -miphoneos-version-min=9.2"
export LDFLAGS="-arch armv7 -arch armv7s -arch arm64 -isysroot $(xcrun --sdk iphoneos --show-sdk-path)"

./configure --prefix=/tmp/out --enable-languages=fortran --host=arm-apple-darwin --disable-shared
…
checking how to run the C preprocessor... /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -E
configure: error: in `/Users/timo/temp/gcc-4.8.5-build/fixincludes':
configure: error: C preprocessor "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -E" fails sanity check
See `config.log' for more details.
make[1]: *** [configure-fixincludes] Error 1

The configure script states that

configure: WARNING: If you wanted to set the --build type, don't use --host.
If a cross compiler is detected then cross compile mode will be used.
  • What is meant by If a cross compiler is detected? How do I define the target platform correctly?
  • LLVM uses -arch armv7 etc. as target definition. What is nedded when using GCC?
1
I don't know about libgfortran alone, but gfortran cannot be built without also building gcc.Vladimir F
> How do I define the target platform correctly? You should use --target. --host sets the host platform, i.e. the one on which the compiler will run.Mikhail Maltsev
@MikhailMaltsev Using --target instead of --host yields to this error: configure: error: cannot run C compiled programs. If you meant to cross compile, use --host.timomeinen
You need to compile and install binutils for arm-apple-darwin before compiling gcc, or to ensure that existing tools (ar, as, ld, etc.) are found.J.J. Hakala
@J.J.Hakala Are the Apple tools found by e.g. xcrun -sdk iphoneos -find ar not capable of the arm-apple-darwin target?timomeinen

1 Answers

1
votes

You are trying to build cross-gcc libraries without cross binutils. Here is a good manual for building cross-gcc for arm, you can follow it.

What is meant by If a cross compiler is detected? How do I define the target platform correctly?

When configuring you should also set --target=arm-apple-darwin. (In my own experience I did not set --host at all)

make[2]: arm-apple-darwin-ar: No such file or directory

Before building arm cross-compiler target libraries you should build binutils for this target.

Can't say anything about llvm.

So just try to make all steps in the link above.