1、準備工作
- objc4-781 源碼
-
依賴的文件
源碼編譯需要依賴的文件
說明:其中除了其中 launchd-106.10 需要在Mac OS X 10.4.4下載,其他的均可以在最新的的版本macOS 10.15中檢索到
2、編譯調(diào)試
下載完源碼解壓直接運行,會出現(xiàn)以下問題:
問題1:unable to find sdk 'macosx.internal'

解決:選擇 target -> objc -> Build Settings -> Base SDK -> 選擇 macOS
注意:【target中的 objc 和 obc-trampolines都需要更改】

每解決一個問題,繼續(xù)編譯
問題2:
'sys/reason.h' file not found
解決:
step1:在Apple source的 macOS10.15 --> xnu-6153.11.26/bsd/sys/reason.h 路徑自行下載
step2:在objc4-781的根目錄下新建Common文件夾, 并在Common文件夾中創(chuàng)建sys文件夾
step3:將 reason.h文件拷貝到sys文件中

step4:設(shè)置文件檢索路徑:選擇 target -> objc -> Build Settings,在工程的 Header Search Paths 中添加搜索路徑 $(SRCROOT)/Common

問題3:'mach-o/dyld_priv.h' file not found
解決:
step1:在Common文件中 創(chuàng)建 mach-o 文件夾
step2:找到文件:dyld-733.6 -- include -- mach-o -- dyld_priv.h
step3:將dyld_priv.h拷貝到 mach-o文件夾中

step4:拷貝到文件夾后,還需要修改 dyld_priv.h 文件,即在 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
問題4:'os/lock_private.h' file not found
解決:
step1:在Common中創(chuàng)建 os文件夾
step2:找到文件libplatform-220 --> private --> os --> lock_private.h 、base_private.h,
step3:將文件拷貝至 os 文件夾中

問題5:'pthread/tsd_private.h' file not found
解決:
step1:在Common文件夾中創(chuàng)建 pthread 文件夾
step2:找到libpthread-416.11.1 --> private --> tsd_private.h、spinlock_private.h文件,
step3:拷貝到 pthread文件夾

問題6:'System/machine/cpu_capabilities.h' file not found
解決:
step1:在Common文件夾中創(chuàng)建System文件夾,并在System文件夾下創(chuàng)建machine文件夾
step2:找到xnu6153.11.26 --> osfmk --> machine --> cpu_capabilities.h文件,
step3:將文件拷貝到machine文件夾下

問題7:'os/tsd.h' file not found
解決:
step1:找到xnu6153.11.26 --> libsyscall --> os --> tsd.h文件,
step2:將文件拷貝到Common-->os文件夾下

問題8:'System/pthread_machdep.h' file not found
解決:
step1: 在Libc-583版本中找到Libc-583/pthreads/pthread_machdep.h,
step2:將文件拷貝到Common--> System

說明:在最新版的macOS 10.15中最新版下載的libc中沒有這個h文件,需要下載Libc-583版本
問題9:'CrashReporterClient.h' file not found
解決:
step1:* 在 Libc-825.24中找到Libc-825.24/include/CrashReporterClient.h
step2:將文件拷貝到Common文件夾下

如果編譯還是報錯,則
需要在 Build Settings -> Preprocessor Macros 中加入:LIBC_NO_LIBCRASHREPORTERCLIENT
問題10:'objc-shared-cache.h' file not found
解決:
step1:找到dyld-733.6 --> include --> objc-shared-cache.h
step2:將文件拷貝到Common文件夾下

問題11:'Block_private.h' file not found
解決:
step1:找到libclosure-74 --> Block_private.h
step2:將文件拷貝到Common文件夾下

問題12:'_simple.h' file not found
解決:
step1:找到libplatform-220 --> private --> _simple.h
step2:將文件拷貝到Common文件夾下

問題13:'kern/restartable.h' file not found
解決:
step1:在Common文件夾下創(chuàng)建kern文件夾
step2:找到xnu-6153.11.26 --> osfmk --> kern -->restartable.h
step3:將文件拷貝到kern文件夾下

問題14:Mismatch in debug-ness macros
解決:
step1:注釋掉objc-runtime.mm中的#error mismatch in debug-ness macros

問題15:ld: can't open order file: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/AppleInternal/OrderFiles/libobjc.order
解決:
step1:在targets-->objc-->Build Settings
step2:在工程的 Order File 中添加搜索路徑 $(SRCROOT)/libobjc.order

問題16:Library not found for -lCrashReporterClient
解決:
step1: target -> objc -> Build Settings
step2:在 Other Linker Flags 中刪除 -lCrashReporterClient ( Debug 和 Release 都刪了)

問題17:SDK "macosx.internal" cannot be located.
解決:
step1: target -> objc -> Build Phases -> Run Script(markgc)
step2: 把腳本文本 macosx.internal 改成 macosx

繼續(xù)編譯,編譯成功
運行
step1: 新建一個target :LBHTest

step2: Targets-->LBHTest-->Build Phases

step3:新建一個LBHPerson類

step4:在main.m中 創(chuàng)建 LBHPerson的對象,進行源碼調(diào)試

