Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What toolchain do I need to cross-compile Clang for iOS

OK, so first of all I know that this can be compiled on iOS (armv7) because I read the documentation. However, I can't find the right toolchain.

So, now, what toolchains I've already tried:

i686-apple-darwin10-cpp-4.2.1
i686-apple-darwin10-g++-4.2.1
i686-apple-darwin10-gcc-4.2.1

The above cross-compiles to x86 (I'm on i386). Works fine. But I don't need it

arm-apple-darwin10-cpp-4.2.1
arm-apple-darwin10-g++-4.2.1
arm-apple-darwin10-gcc-4.2.1

The above compiles fine, but doesn't cross compile to arm as I would have expected, instead, it simply compiles to my current arch.

I'm a real beginner in this matter, in fact this is my first attempt to cross-compile something.

UPDATE:

Here are the commands that I've tried(this is for armv6; armv7 is similar):

configure:

../llvm/configure --host=arm-apple-darwin6 --target=arm-apple-darwin6 
--build=i386-apple-darwin --enable-optimized --disable-debug  
--disable-expensive-checks --disable-doxygen  --disable-threads

env vars:

    export DEVROOT=/Developer/Platforms/iPhoneOS.platform/Developer
export SDKROOT=$DEVROOT/SDKs/iPhoneOS$IOS_BASE_SDK.sdk

export CFLAGS="-arch armv6 -pipe -no-cpp-precomp -isysroot $SDKROOT -miphoneos-version-min=$IOS_DEPLOY_TGT -I$SDKROOT/usr/include/"

    export CPP="$DEVROOT/usr/bin/arm-apple-darwin10-cpp-4.2.1"
export CXX="$DEVROOT/usr/bin/arm-apple-darwin10-g++-4.2.1"
export CXXCPP="$DEVROOT/usr/bin/arm-apple-darwin10-cpp-4.2.1"
export CC="$DEVROOT/usr/bin/arm-apple-darwin10-gcc-4.2.1"
export LD=$DEVROOT/usr/bin/ld
export AR=$DEVROOT/usr/bin/ar
export AS=$DEVROOT/usr/bin/as
export NM=$DEVROOT/usr/bin/nm
export RANLIB=$DEVROOT/usr/bin/ranlib
export LDFLAGS="-L$SDKROOT/usr/lib/"

export CPPFLAGS=$CFLAGS
export CXXFLAGS=$CFLAGS

UPDATE : The purpose of this cross compile is to make an armv7(armv6) library not a command line tool.

YET ANOTHER UPDATE: I used the following:

CC="$DEVROOT/usr/bin/clang"
CXX="$DEVROOT/usr/bin/clang++"

./llvm/configure --host=i386-apple-darwin --target=armv7-apple-darwin --build=armv7-apple-darwin --enable-optimized --disable-debug --disable-expensive-checks --disable-doxygen  --disable-threads --enable-targets=arm 

And I managed to get checking whether we are cross compiling... yes out of the configure tool. However, make still outputs a x86_64 binary:(

like image 349
Rad'Val Avatar asked Sep 21 '11 21:09

Rad'Val


People also ask

How do you cross compile with Clang?

There are two main ways to have a cross-compiler: When you have extracted your cross-compiler from a zip file into a directory, you have to use --sysroot=<path> . The path is the root directory where you have unpacked your file, and Clang will look for the directories bin , lib , include in there.

What is toolchain in cross-compiler?

A cross-compiler is a compiler where the target is different from the host. A toolchain is the set of compiler + linker + librarian + any other tools you need to produce the executable (+ shared libraries, etc) for the target. A debugger and/or IDE may also count as part of a toolchain. So.

What linker does Clang use?

Clang can be configured to use one of several different linkers: GNU ld. GNU gold. LLVM's lld.


1 Answers

In principle your configure invocation looks good. I'm trying to shoot a few typical mistakes:

  1. Did you make clean after every change of architecture?
  2. Why are you so sure that the LD, RANLIB etc. of your host system are fine for cross-compilation? It will overwrite the auto-configured value of LD. (The line reading "export LD=ld" would be at fault here.)
  3. Could you check a typical compiler and a typical linker invocation in the output of make for their correct use of the cross-compilation tools?
like image 105
thiton Avatar answered Nov 03 '22 01:11

thiton