Summary of basic principles of iOS
The purpose of this article is to analyze the loading process of dyLD and understand what else is done at the bottom before main function
primers
-
Create a project, overwrite the load method in ViewController, add a C++ method in main, kcFUnc, what is their print order?
-
Load -> kcFunc -> main -> main
Why is it in this order? Isn’t main an entry function? Why wasn’t Main executed first?
Following this question, let’s explore what else we did before we went to main.
Compilation process and libraries
Before analyzing app startup, we need to understand the compilation process of iOSapp code and dynamic and static libraries.
The build process
The compilation process is shown in the figure below, which is mainly divided into the following steps:
The source file
H,. M, and. CPP files are loadedpretreatment
: Replaces macros, deletes comments, expands header files, and generates.i filescompile
: Converts the. I file to assembly language to generate. S fileassembly
: Converts assembly files to machine code files to generate. O fileslink
: References other libraries in the.o file to generate the final executable