不少小夥伴在探索底層的時候常常很苦惱,只能靠猜想!稍微靈活一點的小夥伴會經過
Apple
提供的源碼來輔助看一下,可是很顯然這不太直觀!若是可以直接編譯調試,像咱們本身的代碼直接 LLDB 調試,流程跟蹤。那簡直不要太爽,因而我編譯瞭如今最新的iOS_objc4-756.2
git
若是想先來體驗一把的小夥伴能夠直接 GitHub 源碼 下載!github
若是你也想親自體驗一把,請你準備條件:macos
以上資料均可以在 Apple source 獲取到。api
首先你下載的iOS_objc4-756.2
直接編譯會報錯以下:xcode
Showing Recent Messages The i386 architecture is deprecated. You should update your ARCHS build setting to remove the i386 architecture.架構
解決: 將
objc
和objc-trampolines
中的Build Settings
選項Architectures
中的值切換爲Standard Architectures(64-bit Intel)
app
'sys/reason.h' file not foundide
這個資料我已經給你們找好了:學習
objc-756.2編譯資料/xnu-4903.241.1/bsd/sys/reason.h
xnu-4903.241.1/bsd/sys/reason.h
路徑自行下載reason.h site:opensource.apple.com
定向檢索把找到的文件加入到工程裏面。例如:ui
KCCommon
文件sys
文件reason.h
文件加入進去目前還不行,必定給咱們的工程設置文件檢索路徑
target
-> objc
-> Build Settings
Header Serach Paths
中添加搜索路徑 $(SRCROOT)/KCCommon
'mach-o/dyld_priv.h' file not found
'os/lock_private.h' file not found
'os/base_private.h' file not found
'pthread/tsd_private.h' file not found
'System/machine/cpu_capabilities.h' file not found
'os/tsd.h' file not found
'pthread/spinlock_private.h' file not found
'System/pthread_machdep.h' file not found
'CrashReporterClient.h' file not found
'objc-shared-cache.h' file not found
'_simple.h' file not found
'Block_private.h' file not found
上面的報錯狀況處理方式都是和 'sys/reason.h' file not found
同樣的解決
文件補漏狀況以下圖:
咱們若是直接導入 Apple source 下載的 CrashReporterClient
仍是會報錯:
'CrashReporterClient.h' file not found
解決:
Build Settings
-> Preprocessor Macros
中加入:LIBC_NO_LIBCRASHREPORTERCLIENT
CrashReporterClient
,這裏面咱們直接更改了裏面的宏信息 #define LIBC_NO_LIBCRASHREPORTERCLIENT
GitHub 源碼 這是修改過的!下面板書我修改了什麼
報錯:Use of undeclared identifier ‘DYLD_MACOSX_VERSION_10_13
在 dyld_priv.h
文件頂部加入一下宏:
#define DYLD_MACOSX_VERSION_10_11 0x000A0B00
#define DYLD_MACOSX_VERSION_10_12 0x000A0C00
#define DYLD_MACOSX_VERSION_10_13 0x000A0D00
#define DYLD_MACOSX_VERSION_10_14 0x000A0E00
複製代碼
Can't open order file: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/AppleInternal/OrderFiles/libobjc.order
target
-> objc
-> Build Settings
Order File
中添加搜索路徑 $(SRCROOT)/libobjc.order
Library not found for -lCrashReporterClient
target
-> objc
-> Build Settings
Other Linker Flags
中刪除 -lCrashReporterClient
( Debug
和 Release
都刪了)Undefined symbol: _objc_opt_class
這個問題是由於要適配新系統:MacOS 10.15, 由於如今筆者寫這一篇文章的時候,尚未正式版本推送!這裏咱們向下兼容 MacOS 10.14
/xcodebuild:1:1: SDK "macosx.internal" cannot be located.
/xcrun:1:1: sh -c '/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -sdk macosx.internal -find clang++ 2> /dev/null' failed with exit code 16384: (null) (errno=No such file or directory)
/xcrun:1:1: unable to find utility "clang++", not a developer tool or in PATH
target
-> objc
-> Build Phases
-> Run Script(markgc)
macosx.internal
改爲 macosx
no such public header file: '/tmp/objc.dst/usr/include/objc/ObjectiveC.apinotes'
target
-> objc
-> Build Settings
Text-Based InstallAPI Verification Model
中添加搜索路徑 Errors Only
Other Text-Based InstallAPI Flags
清空全部內容接下來你能夠編譯 - Build Succeeded
- 恭喜你!💐
可能到這裏你已經老血吐了一地了!的確配置過程仍是相對來講有點噁心,尤爲是文件的查漏補缺,可是咱們享受編譯成功的喜悅吧!
Target
: LGTestiOS 如今更多的會偏向底層開發研究,可調式編譯的 objc4 源碼
可以幫助更快速學習和更容易理解!博客持續更新中,謝謝你們的關注點贊!Thanks♪(・ω・)ノ