Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cross-compile clang/llvm for iOS?

How to cross-compile clang/llvm for iOS? I need to get libclang (.a or .dylib i believe) to use it via C API in my iOS app.

like image 387
4ntoine Avatar asked May 30 '14 04:05

4ntoine


People also ask

Can Clang cross compile?

On the other hand, Clang/LLVM is natively a cross-compiler, meaning that one set of programs can compile to all targets by setting the -target option.

Does Apple use LLVM?

All of Apple's operating systems, iOS, macOS, tvOS and watchOS, are built with LLVM technologies. And Xcode, Apple's integrated development environment, supports development in Swift, C, C++, and Objective-C, all of which use and are built with LLVM technologies.

Can GCC compile LLVM?

By default, llvm-gcc compiles to native objects just like GCC does. If the -emit-llvm and -c options are given then it will generate LLVM bitcode files instead.


1 Answers

# Get LLVM/Clang

mkdir llvm
curl -O http://llvm.org/releases/3.4/llvm-3.4.src.tar.gz
tar xzfv llvm-3.4.src.tar.gz
cd llvm-3.4/tools/
curl -O http://llvm.org/releases/3.4/clang-3.4.src.tar.gz
tar xzfv clang-3.4.src.tar.gz
mv clang-3.4 clang
cd ..

# Assuming Xcode 5.1 (LLVM 3.5+ requires -stdlib=libc++ as well)

export CC="clang -arch armv7 -mios-version-min=5.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk"
export CXX="clang++ -arch armv7 -mios-version-min=5.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk"

mkdir build
cd build

../configure \
  --prefix=/Users/thomas/tmp/llvm-ios \
  --host=arm-apple-darwin11 \
  --enable-optimized \
  --disable-assertions

unset CC CXX # important! (Otherwise the next step will fail)

make VERBOSE=1 -j...

After a while you will get:

/Users/thomas/tmp/llvm-3.4/lib/Support/Unix/Program.inc:46:10: fatal error: 'crt_externs.h' file not found
#include <crt_externs.h> // _NSGetEnviron
         ^

Comment the header file and hack the call to _NSGetEnviron() out (you'll get this three times)

make install
like image 52
Thomas Avatar answered Sep 22 '22 21:09

Thomas