iOS開發(fā)——Xcode編譯過程解析

Xcode

加入到新的團(tuán)隊(duì)后宣增,首先發(fā)現(xiàn)的問題就是項(xiàng)目編譯速度太慢了玫膀!簡直慢到令人發(fā)指,什么概念呢爹脾,當(dāng)你修改了項(xiàng)目的配置文件或者重新 pod install 或者其他改動(dòng)帖旨,導(dǎo)致工程觸發(fā)全量編譯時(shí),編譯時(shí)間居然在30分~40分鐘不等灵妨!

雖然以前了解過一些編譯優(yōu)化的工作解阅,但沒有親自參與過,這一次也算是親自實(shí)踐了泌霍。比較明確的是货抄,在進(jìn)行優(yōu)化之前,首先要做的一定是深入研究一下 Xcode 的編譯過程烹吵,找到導(dǎo)致工程編譯慢的罪魁禍?zhǔn)装谋茫瑢ΠY下藥方能解決問題生蚁。

一個(gè)簡單的 Demo

為了方便輔助介紹 Xcode 的編譯過程,用 Xcode 創(chuàng)建一個(gè)簡單的 single view app藏姐,考慮到采用 Cocoapods 進(jìn)行第三方庫管理已經(jīng)成了幾乎所有 iOS 項(xiàng)目的標(biāo)配呀酸,我這里使用本地源碼創(chuàng)建的一個(gè)本地 pod 來實(shí)驗(yàn)凉蜂。Log 目錄下存在一個(gè) TestLog.podpec 的文件,執(zhí)行 pod install 后,就得到的集成后的工程窿吩,工程結(jié)構(gòu)如下圖所示:


Demo 結(jié)構(gòu)

注茎杂,Podfile 和 podspec 均使用官方命令產(chǎn)出:

pod init
pod spec create TestLog

頁面啟動(dòng)后調(diào)用 XcodeLog 的類方法:+[XcodeLog log],打印一行日志:


運(yùn)行 Demo

ok纫雁,Demo 準(zhǔn)備好了煌往,也運(yùn)行起來了,我們一起看下編譯它過程轧邪。

Demo 編譯過程

Xcode 非常的強(qiáng)大刽脖,強(qiáng)大到整個(gè)編譯細(xì)節(jié)你都可以看到!


消息報(bào)告工具

于是忌愚,我們 cmd + B 后曲管,看到詳細(xì)的編譯日志:


編譯流程

流程大致分為:

  • 編譯 TestLog 這個(gè) Target
  • 編譯 Pods-XcodeDemo 這個(gè) Target
  • 編譯 XcodeDemo 這個(gè)主工程
  • 編譯完成

默認(rèn)情況下,上面細(xì)節(jié)的界面隱藏了大量編譯信息硕糊,我們可以通過點(diǎn)擊每一條單獨(dú)的任務(wù)進(jìn)行展開院水,更詳細(xì)的信息就在這里面了。


編譯詳細(xì)

Target 編譯

  1. Write auxiliary files
    生成一些輔助文件简十,主要是 .hmap檬某、LinkFileList 文件,用于輔助執(zhí)行編譯用的勺远,可以提高二次編譯速度橙喘。
Write auxiliary files

write-file /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/TestLog-all-target-headers.hmap
write-file /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/TestLog-generated-files.hmap
/bin/mkdir -p /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/Objects-normal/x86_64
write-file /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/Objects-normal/x86_64/TestLog.LinkFileList
write-file /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/TestLog-own-target-headers.hmap
write-file /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/TestLog.hmap
write-file /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/TestLog-project-headers.hmap
write-file /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/TestLog-all-non-framework-target-headers.hmap
  1. 編譯 .m 文件
    .m 是主要的源文件,經(jīng)過預(yù)編譯操作后胶逢,這里的 .m 是展開后的厅瞎,可以獨(dú)立編譯生成最后的 .o 文件。
    這里 CompileC 命令和 clang 命令
CompileC /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/Objects-normal/x86_64/XcodeLog.o /Users/ranger/tmp/XcodeDemo/XcodeDemo/Log/XcodeLog.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler
cd /Users/ranger/tmp/XcodeDemo/Pods
export LANG=en_US.US-ASCII
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -arch x86_64 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu11 -fobjc-arc -fobjc-weak -fmodules -fmodules-cache-path=/Users/ranger/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -fbuild-session-file=/Users/ranger/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -fmodules-validate-once-per-build-session -Wnon-modular-include-in-framework-module -Werror=non-modular-include-in-framework-module -Wno-trigraphs -fpascal-strings -O0 -fno-common -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wdocumentation -Wunreachable-code -Wno-implicit-atomic-properties -Werror=deprecated-objc-isa-usage -Werror=objc-root-class -Wno-arc-repeated-use-of-weak -Wimplicit-retain-self -Wduplicate-method-match -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wuninitialized -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wno-float-conversion -Wnon-literal-null-conversion -Wobjc-literal-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wdeprecated-implementations -DPOD_CONFIGURATION_DEBUG=1 -DDEBUG=1 -DCOCOAPODS=1 -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.4.sdk -fasm-blocks -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -mios-simulator-version-min=9.0 -g -Wno-sign-conversion -Winfinite-recursion -Wcomma -Wblock-capture-autoreleasing -Wstrict-prototypes -Wunguarded-availability -fobjc-abi-version=2 -fobjc-legacy-dispatch -index-store-path /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Index/DataStore -iquote /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/TestLog-generated-files.hmap -I/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/TestLog-own-target-headers.hmap -I/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/TestLog-all-target-headers.hmap -iquote /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/TestLog-project-headers.hmap -I/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Products/Debug-iphonesimulator/TestLog/include -I/Users/ranger/tmp/XcodeDemo/Pods/Headers/Private -I/Users/ranger/tmp/XcodeDemo/Pods/Headers/Private/TestLog -I/Users/ranger/tmp/XcodeDemo/Pods/Headers/Public -I/Users/ranger/tmp/XcodeDemo/Pods/Headers/Public/TestLog -I/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/DerivedSources/x86_64 -I/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/DerivedSources -F/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Products/Debug-iphonesimulator/TestLog -include /Users/ranger/tmp/XcodeDemo/Pods/Target\ Support\ Files/TestLog/TestLog-prefix.pch -MMD -MT dependencies -MF /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/Objects-normal/x86_64/XcodeLog.d --serialize-diagnostics /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/Objects-normal/x86_64/XcodeLog.dia -c /Users/ranger/tmp/XcodeDemo/XcodeDemo/Log/XcodeLog.m -o /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/Objects-normal/x86_64/XcodeLog.o
  1. 編譯 xxx-dummy.m 文件
    xxx-dummy.m 文件是 CocoaPods 使用的用于區(qū)分不同 pod 的編譯文件初坠,每個(gè)第三方庫有不同的 target和簸,所以每次編譯第三方庫時(shí),都會(huì)新增幾個(gè)文件:包含編譯選項(xiàng)的.xcconfig文件碟刺,同時(shí)擁有編譯設(shè)置和 CocoaPods 配置的私有 .xcconfig 文件锁保,編譯所必須的prefix.pch文件以及編譯必須的文件 dummy.m
CompileC /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/Objects-normal/x86_64/TestLog-dummy.o Target\ Support\ Files/TestLog/TestLog-dummy.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler
cd /Users/ranger/tmp/XcodeDemo/Pods
export LANG=en_US.US-ASCII
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -arch x86_64 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu11 -fobjc-arc -fobjc-weak -fmodules -fmodules-cache-path=/Users/ranger/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -fbuild-session-file=/Users/ranger/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -fmodules-validate-once-per-build-session -Wnon-modular-include-in-framework-module -Werror=non-modular-include-in-framework-module -Wno-trigraphs -fpascal-strings -O0 -fno-common -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wdocumentation -Wunreachable-code -Wno-implicit-atomic-properties -Werror=deprecated-objc-isa-usage -Werror=objc-root-class -Wno-arc-repeated-use-of-weak -Wimplicit-retain-self -Wduplicate-method-match -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wuninitialized -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wno-float-conversion -Wnon-literal-null-conversion -Wobjc-literal-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wdeprecated-implementations -DPOD_CONFIGURATION_DEBUG=1 -DDEBUG=1 -DCOCOAPODS=1 -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.4.sdk -fasm-blocks -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -mios-simulator-version-min=9.0 -g -Wno-sign-conversion -Winfinite-recursion -Wcomma -Wblock-capture-autoreleasing -Wstrict-prototypes -Wunguarded-availability -fobjc-abi-version=2 -fobjc-legacy-dispatch -index-store-path /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Index/DataStore -iquote /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/TestLog-generated-files.hmap -I/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/TestLog-own-target-headers.hmap -I/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/TestLog-all-target-headers.hmap -iquote /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/TestLog-project-headers.hmap -I/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Products/Debug-iphonesimulator/TestLog/include -I/Users/ranger/tmp/XcodeDemo/Pods/Headers/Private -I/Users/ranger/tmp/XcodeDemo/Pods/Headers/Private/TestLog -I/Users/ranger/tmp/XcodeDemo/Pods/Headers/Public -I/Users/ranger/tmp/XcodeDemo/Pods/Headers/Public/TestLog -I/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/DerivedSources/x86_64 -I/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/DerivedSources -F/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Products/Debug-iphonesimulator/TestLog -include /Users/ranger/tmp/XcodeDemo/Pods/Target\ Support\ Files/TestLog/TestLog-prefix.pch -MMD -MT dependencies -MF /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/Objects-normal/x86_64/TestLog-dummy.d --serialize-diagnostics /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/Objects-normal/x86_64/TestLog-dummy.dia -c /Users/ranger/tmp/XcodeDemo/Pods/Target\ Support\ Files/TestLog/TestLog-dummy.m -o /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/Objects-normal/x86_64/TestLog-dummy.o
  1. 創(chuàng)建靜態(tài)庫
    創(chuàng)建當(dāng)前架構(gòu)的靜態(tài)庫,例如栗子中用的是模擬器半沽,對應(yīng)的是 x86_64 架構(gòu)爽柒。
Libtool /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Products/Debug-iphonesimulator/TestLog/libTestLog.a normal x86_64
cd /Users/ranger/tmp/XcodeDemo/Pods
export IPHONEOS_DEPLOYMENT_TARGET=9.0
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static -arch_only x86_64 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.4.sdk -L/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Products/Debug-iphonesimulator/TestLog -filelist /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/TestLog.build/Objects-normal/x86_64/TestLog.LinkFileList -o /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Products/Debug-iphonesimulator/TestLog/libTestLog.a
  1. 拷貝頭文件
    將所有的頭文件拷貝到 Pods 目錄對應(yīng)的 pod 里,沒有頭文件配合使用的二進(jìn)制庫是不能使用的者填。
CpHeader /Users/ranger/tmp/XcodeDemo/XcodeDemo/Log/XcodeLog.h /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Products/Debug-iphonesimulator/TestLog/XcodeLog.h
cd /Users/ranger/tmp/XcodeDemo/Pods
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
builtin-copy -exclude .DS_Store -exclude CVS -exclude .svn -exclude .git -exclude .hg -resolve-src-symlinks /Users/ranger/tmp/XcodeDemo/XcodeDemo/Log/XcodeLog.h /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Products/Debug-iphonesimulator/TestLog
  1. 拷貝資源文件(如果有)

主工程編譯

  1. Write auxiliary files
  2. Process product packaging
  3. 執(zhí)行 cocoapods 資源拷貝腳本
  4. 編譯 .m 文件
  5. 鏈接靜態(tài)庫
  6. 編譯資源文件
  7. Process info.plist file
  8. 執(zhí)行 cocoapods 資源拷貝腳本
  9. 創(chuàng)建 .app
  10. 打包及簽名

仔細(xì)觀察

我們知道浩村,XcodeDemo 是工程的主 Target,那 TestLog 和 Pods-XcodeDemo 是哪兒來的呢占哟?
嗯心墅,了解 CocoaPods 原理的同學(xué)都知道酿矢,CocoaPods 創(chuàng)建了 Pods 工程,引入新的工程來隱藏第三方庫的依賴怎燥,從而管理第三方 pods瘫筐。簡單說就是主工程依賴 Pods 工程,Pods 工程依賴子
pods铐姚,從而間接被主工程依賴策肝。而新的 Target 就是 CocoaPods 創(chuàng)建的。

仔細(xì)觀察編譯過程隐绵,我們會(huì)發(fā)現(xiàn)驳糯,除了主工程直接生成最終的 .app 外,其他工程(Target)都會(huì)編譯成一個(gè)靜態(tài)庫被主工程去 Link氢橙,如果某個(gè)工程特別大酝枢,包含眾多的 .m 文件或者其他資源文件,那么 Xcode 就會(huì)花費(fèi)較多的時(shí)間去編譯悍手。


創(chuàng)建靜態(tài)庫1

創(chuàng)建靜態(tài)庫2

而在 Link 階段帘睦,Xcode 會(huì)將前面創(chuàng)建的所有二進(jìn)制文件做一次鏈接得到最后的二進(jìn)制包

Ld /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Products/Debug-iphonesimulator/XcodeDemo.app/XcodeDemo normal x86_64
cd /Users/ranger/tmp/XcodeDemo
export IPHONEOS_DEPLOYMENT_TARGET=9.0
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.4.sdk -L/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Products/Debug-iphonesimulator -L/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Products/Debug-iphonesimulator/TestLog -F/Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Products/Debug-iphonesimulator -filelist /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/XcodeDemo.build/Debug-iphonesimulator/XcodeDemo.build/Objects-normal/x86_64/XcodeDemo.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -mios-simulator-version-min=9.0 -dead_strip -Xlinker -object_path_lto -Xlinker /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/XcodeDemo.build/Debug-iphonesimulator/XcodeDemo.build/Objects-normal/x86_64/XcodeDemo_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -Xlinker -objc_abi_version -Xlinker 2 -fobjc-arc -fobjc-link-runtime -ObjC -lTestLog -Xlinker -sectcreate -Xlinker __TEXT -Xlinker __entitlements -Xlinker /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/XcodeDemo.build/Debug-iphonesimulator/XcodeDemo.build/XcodeDemo.app-Simulated.xcent -lPods-XcodeDemo -Xlinker -dependency_info -Xlinker /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Intermediates.noindex/XcodeDemo.build/Debug-iphonesimulator/XcodeDemo.build/Objects-normal/x86_64/XcodeDemo_dependency_info.dat -o /Users/ranger/Library/Developer/Xcode/DerivedData/XcodeDemo-fmyuqhxixlpjqqdzsflmuzdvhmgt/Build/Products/Debug-iphonesimulator/XcodeDemo.app/XcodeDemo

整體流程大概就是這樣,即使再復(fù)雜的工程坦康,也是類似的流程和操作竣付。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市滞欠,隨后出現(xiàn)的幾起案子古胆,更是在濱河造成了極大的恐慌,老刑警劉巖筛璧,帶你破解...
    沈念sama閱讀 206,968評(píng)論 6 482
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件逸绎,死亡現(xiàn)場離奇詭異,居然都是意外死亡夭谤,警方通過查閱死者的電腦和手機(jī)棺牧,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,601評(píng)論 2 382
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來朗儒,“玉大人颊乘,你說我怎么就攤上這事∽沓” “怎么了乏悄?”我有些...
    開封第一講書人閱讀 153,220評(píng)論 0 344
  • 文/不壞的土叔 我叫張陵,是天一觀的道長恳不。 經(jīng)常有香客問我檩小,道長,這世上最難降的妖魔是什么妆够? 我笑而不...
    開封第一講書人閱讀 55,416評(píng)論 1 279
  • 正文 為了忘掉前任识啦,我火速辦了婚禮,結(jié)果婚禮上神妹,老公的妹妹穿的比我還像新娘颓哮。我一直安慰自己,他們只是感情好鸵荠,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,425評(píng)論 5 374
  • 文/花漫 我一把揭開白布冕茅。 她就那樣靜靜地躺著,像睡著了一般蛹找。 火紅的嫁衣襯著肌膚如雪姨伤。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,144評(píng)論 1 285
  • 那天庸疾,我揣著相機(jī)與錄音乍楚,去河邊找鬼。 笑死届慈,一個(gè)胖子當(dāng)著我的面吹牛徒溪,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播金顿,決...
    沈念sama閱讀 38,432評(píng)論 3 401
  • 文/蒼蘭香墨 我猛地睜開眼臊泌,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了揍拆?” 一聲冷哼從身側(cè)響起渠概,我...
    開封第一講書人閱讀 37,088評(píng)論 0 261
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎嫂拴,沒想到半個(gè)月后播揪,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 43,586評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡筒狠,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,028評(píng)論 2 325
  • 正文 我和宋清朗相戀三年剪芍,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片窟蓝。...
    茶點(diǎn)故事閱讀 38,137評(píng)論 1 334
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡罪裹,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出运挫,到底是詐尸還是另有隱情状共,我是刑警寧澤,帶...
    沈念sama閱讀 33,783評(píng)論 4 324
  • 正文 年R本政府宣布谁帕,位于F島的核電站峡继,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏匈挖。R本人自食惡果不足惜碾牌,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,343評(píng)論 3 307
  • 文/蒙蒙 一康愤、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧舶吗,春花似錦征冷、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,333評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至腹侣,卻和暖如春叔收,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背傲隶。 一陣腳步聲響...
    開封第一講書人閱讀 31,559評(píng)論 1 262
  • 我被黑心中介騙來泰國打工饺律, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人跺株。 一個(gè)月前我還...
    沈念sama閱讀 45,595評(píng)論 2 355
  • 正文 我出身青樓蓝晒,卻偏偏與公主長得像,于是被迫代替她去往敵國和親帖鸦。 傳聞我的和親對象是個(gè)殘疾皇子芝薇,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,901評(píng)論 2 345