Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I cross-compile GCC to produce libgfortran for iOS devices (arm, armv7)?

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?
like image 804
timomeinen Avatar asked Jan 24 '16 09:01

timomeinen


1 Answers

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.

like image 98
alexanius Avatar answered Oct 31 '22 15:10

alexanius