想着可以实现直接用编译器编译一个文件,然后拷贝到安装上运行,以实现某些功能。
目的:实现一个命令编译可以在安卓上运行的可执行c/c++可执行程序
首先在工程external目录下创建mytest目录,在mytest目录添加Andorid.bp, myhello.c文件
Andorid.bp:
cc_binary {
name: "myhelloworld",
cflags:["--verbose",
"-g",
],
ldflags:["--verbose",
"-g",
],
srcs: ["myhello.c"],
}
myhello.c
int main()
{
printf("hello andorid");
return 0;
}
编辑完成后回到主目录执行
source build/envsetup.sh
lunch 36
mm myhelloworld &> 1.txt //log存到1.txt中
执行完成后,可以看到编译和链接myhello.c文件的详细信息以及编译器信息;
编译:"prebuilts/clang/host/linux-x86/clang-r383902b/bin/clang.real" -cc1 -triple thumbv8-unknown-linux-android10000 -emit-obj -mnoexecstack -disable-free -disable-llvm-verifier -discard-value-names -main-file-name myhello.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mthread-model posix -mframe-pointer=none -relaxed-aliasing -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu cortex-a53 -target-feature +soft-float-abi -target-feature +crc -target-feature -sha2 -target-feature -aes -target-feature -dotprod -target-feature +dsp -target-feature -mve -target-feature -mve.fp -target-feature -ras -target-feature -sb -target-feature -lob -target-feature +hwdiv-arm -target-feature +hwdiv -target-feature +vfp2 -target-feature +vfp2sp -target-feature +vfp3 -target-feature +vfp3d16 -target-feature +vfp3d16sp -target-feature +vfp3sp -target-feature +fp16 -target-feature +vfp4 -target-feature +vfp4d16 -target-feature +vfp4d16sp -target-feature +vfp4sp -target-feature +fp-armv8 -target-feature +fp-armv8d16 -target-feature +fp-armv8d16sp -target-feature +fp-armv8sp -target-feature -fullfp16 -target-feature +fp64 -target-feature +d32 -target-feature +neon -target-feature -crypto -target-feature -fp16fml -target-abi aapcs-linux -mfloat-abi soft -fallow-half-arguments-and-returns -dwarf-column-info -fno-split-dwarf-inlining -debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -v -ffunction-sections -fdata-sections -nostdsysteminc -resource-dir prebuilts/clang/host/linux-x86/clang-r383902b/lib64/clang/11.0.2 -dependency-file out/soong/.intermediates/external/mytest/myhelloworld/android_arm_armv8-a_cortex-a53/obj/external/mytest/myhello.o.d -MT out/soong/.intermediates/external/mytest/myhelloworld/android_arm_armv8-a_cortex-a53/obj/external/mytest/myhello.o -sys-header-deps -isystem bionic/libc/include -isystem bionic/libc/kernel/uapi -isystem bionic/libc/kernel/uapi/asm-arm -isystem bionic/libc/kernel/android/scsi -isystem bionic/libc/kernel/android/uapi -D ANDROID -D NDEBUG -U DEBUG -D __compiler_offsetof=__builtin_offsetof -D _FORTIFY_SOURCE=2 -D __ARM_FEATURE_LPAE=1 -I external/mytest -D __LIBC_API__=10000 -D __LIBM_API__=10000 -D __LIBDL_API__=10000 -I external/libcxxabi/include -I external/libcxx/include -I bionic/libc/include -I system/core/include -I system/media/audio/include -I hardware/libhardware/include -I hardware/libhardware_legacy/include -I hardware/ril/include -I frameworks/native/include -I frameworks/native/opengl/include -I frameworks/av/include -I libnativehelper/include_jni -internal-isystem prebuilts/clang/host/linux-x86/clang-r383902b/lib64/clang/11.0.2/include -O2 -Wno-enum-compare -Wno-enum-compare-switch -Wno-null-pointer-arithmetic -Wno-null-dereference -Wno-pointer-compare -Wno-xor-used-as-pow -Wno-final-dtor-non-final-class -W -Wall -Wno-unused -Winit-self -Wpointer-arith -Wno-multichar -Werror=date-time -Werror=pragma-pack -Werror=pragma-pack-suspicious-include -Werror=int-conversion -Wno-reserved-id-macro -Wno-unused-command-line-argument -Wno-sign-compare -Wno-defaulted-function-deleted -Wno-inconsistent-missing-override -Wno-c99-designator -Wstrict-aliasing=2 -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Werror=format-security -Wall -Werror -Werror=int-to-pointer-cast -Werror=pointer-to-int-cast -Werror=fortify-source -Werror=address-of-temporary -Werror=return-type -Wno-tautological-constant-compare -Wno-tautological-type-limit-compare -Wno-reorder-init-list -Wno-implicit-int-float-conversion -Wno-int-in-bool-context -Wno-sizeof-array-div -Wno-tautological-overlap-compare -Wno-deprecated-copy -Wno-range-loop-construct -Wno-misleading-indentation -Wno-zero-as-null-pointer-constant -Wno-deprecated-anon-enum-enum-conversion -Wno-deprecated-enum-enum-conversion -Wno-string-compare -Wno-enum-enum-conversion -Wno-enum-float-conversion -Wno-pessimizing-move -std=gnu99 -fdebug-compilation-dir /proc/self/cwd -fdebug-prefix-map=/proc/self/cwd= -ferror-limit 19 -fmessage-length 0 -stack-protector 2 -ftrivial-auto-var-init=zero -fno-signed-char -fgnuc-version=4.2.1 -fexperimental-new-pass-manager -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -o out/soong/.intermediates/external/mytest/myhelloworld/android_arm_armv8-a_cortex-a53/obj/external/mytest/myhello.o -x c external/mytest/myhello.c
链接:
"/home/nuos/code/code_m7/prebuilts/clang/host/linux-x86/clang-r383902b/bin/ld.lld" -pie -z noexecstack -EL --warn-shared-textrel -z now -z relro -X --hash-style=gnu --enable-new-dtags --eh-frame-hdr -m armelf_linux_eabi -dynamic-linker /system/bin/linker -o out/soong/.intermediates/external/mytest/myhelloworld/android_arm_armv8-a_cortex-a53/unstripped/myhelloworld -L/home/nuos/code/code_m7/prebuilts/clang/host/linux-x86/clang-r383902b/lib64/clang/11.0.2/lib/linux/arm -L/home/nuos/code/code_m7/prebuilts/clang/host/linux-x86/clang-r383902b/bin/../lib -L/lib/../lib -L/usr/lib/../lib -L/home/nuos/code/code_m7/prebuilts/clang/host/linux-x86/clang-r383902b/bin/../lib -L/lib -L/usr/lib out/soong/.intermediates/bionic/libc/crtbegin_dynamic/android_arm_armv8-a_cortex-a53/crtbegin_dynamic.o out/soong/.intermediates/external/mytest/myhelloworld/android_arm_armv8-a_cortex-a53/obj/external/mytest/myhello.o out/soong/.intermediates/external/libcxxabi/libc++demangle/android_arm_armv8-a_cortex-a53_static/libc++demangle.a --start-group prebuilts/clang/host/linux-x86/clang-r383902b/lib64/clang/11.0.2/lib/linux/libclang_rt.builtins-arm-android.a prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/arm-linux-androideabi/lib/libatomic.a --end-group out/soong/.intermediates/external/libcxx/libc++/android_arm_armv8-a_cortex-a53_shared/libc++.so out/soong/.intermediates/bionic/libc/libc/android_arm_armv8-a_cortex-a53_shared_10000/libc.so out/soong/.intermediates/bionic/libm/libm/android_arm_armv8-a_cortex-a53_shared_10000/libm.so out/soong/.intermediates/bionic/libdl/libdl/android_arm_armv8-a_cortex-a53_shared_10000/libdl.so out/soong/.intermediates/bionic/libc/crtend_android/android_arm_armv8-a_cortex-a53/obj/bionic/libc/arch-common/bionic/crtend.o -z noexecstack -z relro -z now --build-id=md5 --warn-shared-textrel --fatal-warnings --no-undefined-version --exclude-libs libgcc.a --exclude-libs libgcc_stripped.a --exclude-libs libunwind_llvm.a --pack-dyn-relocs=android+relr --use-android-relr-tags --no-undefined --icf=safe --hash-style=gnu -m armelf --exclude-libs=libclang_rt.builtins-arm-android.a --gc-sections -z nocopyreloc --exclude-libs libunwind_llvm.a -dynamic-linker /system/bin/linker
从以上log 可以看出编译器使用的是prebuilts/clang/host/linux-x86/clang-r383902b