Tuesday, January 28, 2014

understanding clang cross-compiing

I try to unify the dev environment to clang as I might work on IOS where gcc might not available. So far, clang works for most of my porting. Usually, libs work with gcc by default. clang can replace gcc in most of cases of native compiling, with some minor patches some times. However, crossing compie with clang is not trivial.

I dug into the android-cmake log to find the way of cross-compiling. The procedure seems that clang compile the source code to some bitcode, and then ndk/gcc/as compiles the bitcode to arm binary. clang can not work along to get arm binary.

Maybe I just use gcc for everything to save my live, as I might not work on IOS in a short time.

Update:
I try to manually compile arm binary on x86_64 with following commands:

clang -target armv7a-none-eabi -mcpu=cortex-a8 --sysroot=/opt/android-ndk/platforms/android-19/arch-arm/ -S hello.c

/opt/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-as -mfpu=neon -mfloat-abi=softfp -march=armv7-a -mfpu=vfpv3-d16 hello.s -o hello.o

/opt/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld hello.o -o hello -L $ANDROID_NDK/platforms/android-19/arch-arm/usr/lib/ -lc -lm

I got an arm binary, but I can not test it, as my tablet does not allow binary to run natively.

No comments:

Post a Comment