Previous Article (Android native C Module compilation)
), We tried to pass the standard
Android. mk
File to compile
C
Module. Next we will try to use it directly.
Gcc
To understand the details of the android compiling environment.
.
Clean:
Android Compilation
Environment provides
"Showcommands"
Option to display the compiled command line,
We can open this option to view some compilation details. Of course, before that
Helloworld
Module
Clean:
# Make clean-helloworld
The above
"Make clean-$ (local_module )"
Yes
Android Compilation
Environment
Make clean
.
Showcommands:
Next, use
Showcommands
Option
Recompile
Helloworld:
# Make helloworld showcommands <br/> build/CORE/product_config.mk: 229: Warning: adding test OTA key <br/> Target thumb C: helloworld <= Development/Hello/hello. c <br/> pre built/linux-x86/toolchain/arm-eabi-4.2.1/bin/ARM-Eabi-gcc-I system/CORE/include-I Hardware/libhardware/include-I Hardware/RIL/ include-I Dalvik/libnativehelper/include-I frameworks/base/include-I external/skia/include-I out/target/product/generic/obj/include-I bionic/libc /arch-arm/include-I bionic/libc/include-I bionic/libstdc ++/include-I bionic/libc/kernel/common-I bionic/libc/kernel/Arch -Arm-I bionic/libm/include/ARCH/ARM-I bionic/libthread_db/include-I development/Hello-I out/target/product/ generic/obj/executables/helloworld_intermediates-C-fno-exceptions-wno-multichar-March = armv5te-mtune = XScale-msoft-float-FPIC-mthumb-interwork-ffunction-sections- funwind-tables-fstack-protector-dctor arm_arch_5 _-d1_arm_arch_5t _-blank _-d1_arm_arch_5te _-include system/CORE/include/ARCH/Linux-arm/androidconfig. h-dandroid-fmessage-length = 0-w-wall-wno-unused-dsk_release-dndebug-O2-g-wstrict-aliasing = 2-Finline-functions-fno-inline- functions-called-once-fgcse-after-reload-frerun-CSE-after-loop-frename-registers-dndebug-udebug-mthumb-OS-fomit-frame-pointer-fno- strict-aliasing-Finline-Limit = 64-MD-O out/target/product/generic/obj/executables/helloworld_intermediates/hello. o development/Hello/hello. c <br/> Target executable: helloworld (Out/target/product/generic/obj/executables/helloworld_intermediates/linked/helloworld) <br/> pre built/linux-x86/toolchain/arm-eabi-4.2.1/bin/ARM-Eabi-G ++-nostdlib-bdynamic-wl,-T, build/CORE/armelf. x-wl,-dynamic-linker,/system/bin/linker-wl, -- GC-sections-wl,-Z, nocopyreloc-O out/target/product/generic/obj/executables/helloworld_intermediates/linked/helloworld-lout/target/product/generic/obj/lib-wl, -rpath-link = out/target/product/generic/obj/lib-LC-lstdc ++-lm out/target/product/generic/obj/lib/crtbegin_dynamic.o out/Target /product/generic/obj/executables/helloworld_intermediates/hello. o-wl, -- no-undefined prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin /.. /lib/GCC/ARM-Eabi/4.2.1/interwork/libgcc. A out/target/product/generic/obj/lib/crtend_android.o <br/> target non-prelinked: helloworld (Out/target/product/generic/symbols/system/bin/helloworld) <br/> out/host/linux-x86/bin/ACP-FPT out/target/product/generic/obj/executables/helloworld_intermediates/linked/helloworld out/target/product/generic/ symbols/system/bin/helloworld <br/> Target Strip: helloworld (Out/target/product/generic/obj/executables/helloworld_intermediates/helloworld) <br/> out/host/linux-x86/bin/soslim -- strip -- shady -- Quiet out/target/product/generic/symbols/system/bin/helloworld -- OUTFILE out/target/ product/generic/obj/executables/helloworld_intermediates/helloworld <br/> install: out/target/product/generic/system/bin/helloworld <br/> out/host/linux-x86/bin/ACP-FPT out/target/product/generic/obj/executables/ helloworld_intermediates/helloworld out/target/product/generic/system/bin/helloworld
As shown in the preceding command line,
Android Compilation
The cross-compilation tool chain used by the environment is
Prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/ARM-Eabi-gcc
,
-I
And
-L
The parameter specifies
C
The library header file and the dynamic library file path are
Bionic/libc/include
And
Out/target/product/generic/obj/lib
And many other compilation options and
-D
The pre-compiled macro defined.
Manual compilation:
We can use the above compilation command to simplify the manual compilation.
Helloworld
Program. Manually delete the last compiled
Helloworld
Program:
# Rm out/target/product/generic/obj/executables/helloworld_intermediates/Hello. O <br/> # rm out/target/product/generic/system/bin/helloworld
Reuse
Gcc
Compile and generate the target file:
# Prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/ARM-Eabi-gcc-I bionic/libc/arch-arm/include-I bionic/libc/ kernel/common-I bionic/libc/kernel/arch-arm-C-fno-tions-wno-multichar-March = armv5te-mtune = XScale-msoft-float-FPIC-mthumb -interwork-ffunction-sections-funwind-tables-fstack-protector-d1_arm_arch_5 _-d1_arm_arch_5t _-character _-d1_arm_arch_5te _-include system/CORE/include/ARCH/ linux-arm/androidconfig. h-dandroid-fmessage-length = 0-w-wall-wno-unused-dsk_release-dndebug-O2-g-wstrict-aliasing = 2-Finline-functions-fno-inline- functions-called-once-fgcse-after-reload-frerun-CSE-after-loop-frename-registers-dndebug-udebug-mthumb-OS-fomit-frame-pointer-fno- strict-aliasing-Finline-Limit = 64-MD-O out/target/product/generic/obj/executables/helloworld_intermediates/hello. o development/Hello/hello. c
And
Android. mk
Compilation Parameter comparison, which mainly reduces unnecessary
-I
Parameters.
Next, generate the executable file:
# Pre built/linux-x86/toolchain/arm-eabi-4.2.1/bin/ARM-Eabi-gcc-nostdlib-bdynamic-wl,-T, build/CORE/armelf. x-wl,-dynamic-linker,/system/bin/linker-wl, -- GC-sections-wl,-Z, nocopyreloc-O out/target/product/generic/obj/executables/helloworld_intermediates/linked/helloworld-lout/target/product/generic/obj/lib-wl, -rpath-link = out/target/product/generic/obj/lib-LC-lm out/target/product/generic/obj/executables/helloworld_intermediates/hello. O out/target/product/generic/obj/lib/crtbegin_dynamic.o-wl, -- no-undefined. /prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin /.. /lib/GCC/ARM-Eabi/4.2.1/interwork/libgcc. A out/target/product/generic/obj/lib/crtend_android.o
It is worth noting that the parameter"
-Wl,-dynamic-linker,/system/bin/linker
", It specifies
Android
Dedicated dynamic linker
/System/bin/linker
Instead
LD. So
.
View results:
The generated executable program is available.
File
And
Readelf
Command to view:
# File out/target/product/generic/obj/executables/helloworld_intermediates/linked/helloworld <br/> out/target/product/generic/obj/executables/helloworld_intermediates/linked/helloworld: elf 32-bit LSB executable, arm, Version 1 (sysv), dynamically linked (uses SHARED libs ), not stripped <br/> # readelf-d out/target/product/generic/obj/executables/helloworld_intermediates/linked/helloworld | grep needed <br/> 0x00000001 (needed) shared Library: [libc. so] <br/> 0x00000001 (needed) Shared Library: [libm. so]
This is
Arm
Format dynamic link executable file, required during running
Libc. So
And
Libm. So
. "
Not stripped
"Indicates it has not been
Strip
.
In embedded systems, compiled executable files or dynamic libraries are usually used to save space.
Strip
Remove the redundant symbol table information. In front of"
Make helloworld showcommands
"We can also see at the end of the command,
Android Compilation
Environment used
Out/host/linux-x86/bin/soslim
Tool
Strip
.
Original article connection:
Http://www.top-e.org/jiaoshi/html/161.html
Related
Android toolchain
For more information, see:
Android toolchain and
Bionic libc