gcc手动编译android可执行程序

    gcc手动编译android可执行程序
    作者:hws000(hws.000#163.com)
    声明:版权所有,转载请联系作者。
    出处:http://blog.csdn.net/hws000/article/details/18984779


1.首先通过Android.mk编译源文件,确保可以正常编译。在LOCAL_CFLAGS中添加-v,可以在mm编译时打印详细的gcc参数,通过这些参数中筛选需要的-I头文件、-l库文件等。具体如下:
arm-eabi-gcc -o array array_test.c -I ../bionic/libc/include -I ../bionic/libc/arch-arm/include -I ../bionic/libc/kernel/arch-arm/ -I ../bionic/libc/kernel/common/ -I ../bionic/libm/include/ -L ../out/debug/target/product/generic_armv5/system/lib -std=c99 -fno-short-enums -march=armv5te -mtune=xscale -mthumb -lm
prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/../../../../arm-eabi/bin/ld: crt0.o: No such file: No such file or directory
collect2: ld returned 1 exit status


2.提示crt0.o的错误是因为gcc链接的默认的系统标准启动文件和标准库文件,应当指定为android实际提供的。修改后的编译参数如下:
arm-eabi-gcc -o array array_test.c -I ../bionic/libc/include -I ../bionic/libc/arch-arm/include -I ../bionic/libc/kernel/arch-arm/ -I ../bionic/libc/kernel/common/ -I ../bionic/libm/include/ -L ../out/debug/target/product/generic_armv5/system/lib -Wl,-rpath-link ../out/debug/target/product/generic_armv5/system/lib -std=c99 -fno-short-enums -march=armv5te -mtune=xscale -mthumb -lm -nostdlib ../out/debug/target/product/generic_armv5/obj/lib/crtbegin_dynamic.o ../out/debug/target/product/generic_armv5/obj/lib/crtend_android.o


3.编译通过的array执行时提示/system/bin/sh: ./array1: No such file or directory。使用正确的linker即可解决。最终的参数如下:
arm-eabi-gcc -o array array_test.c -I ../bionic/libc/include -I ../bionic/libc/arch-arm/include -I ../bionic/libc/kernel/arch-arm/ -I ../bionic/libc/kernel/common/ -I ../bionic/libm/include/ -L ../out/debug/target/product/generic_armv5/system/lib -Wl,-rpath-link ../out/debug/target/product/generic_armv5/system/lib -std=c99 -fno-short-enums -march=armv5te -mtune=xscale -mthumb -lm -nostdlib ../out/debug/target/product/generic_armv5/obj/lib/crtbegin_dynamic.o ../out/debug/target/product/generic_armv5/obj/lib/crtend_android.o -Wl,-dynamic-linker,/system/bin/linker

你可能感兴趣的:(android)