1、準備工作
2、下載源碼 --https://opensource.apple.com/tarballs/objc4/
3、下載其他依賴的庫文件--https://opensource.apple.com/tarballs/
dyld-635.2:https://opensource.apple.com/tarballs/dyld/
launchd-842.92.1:https://opensource.apple.com/tarballs/launchd/
libauto-187:https://opensource.apple.com/tarballs/libauto/
Libc-1272.200.26:https://opensource.apple.com/tarballs/Libc/
libdispatch-1008.220.2:https://opensource.apple.com/tarballs/libdispatch/
libclosure-73:https://opensource.apple.com/tarballs/libclosure/
libpthread-330.220.2:https://opensource.apple.com/tarballs/libpthread/
xnu-4903.221.2:https://opensource.apple.com/tarballs/xnu/
libplatform-177.200.16:https://opensource.apple.com/tarballs/libplatform/
? ? 下載完之后解壓到一個文件夾里,供后面項目編譯來查找缺失的文件
Xcode打開<i>objc.xcodeproj</i>工程文件,command + B編譯
問題1? ?
?解決:
問題2
解決 首先在當前項目中創建Common文件夾用于存放編譯缺失的文件,根據編譯錯誤提示可以知道,reason.h是在sys路徑下的,再在Common下再創建sys文件夾,然后在項目中配置頭文件搜索路徑路徑
在之前下載好的文件夾里找到reason.h,把文件引入到sys路徑下
查找文件方式1:直接在之前下載好的文件夾里直接搜索文件名
方式2:命令行搜索 — find . name ‘reason.h'
問題3 再次編譯
解決 ?跟問題2一樣,在Common下創建文件夾—>搜索文件—>添加到項目中(后面類似錯誤就不在貼圖,只貼錯誤提示出來)
問題4 ?錯誤提示'os/lock_private.h' file not found
解決 創建os文件夾,添加lock_private.h文件
問題5 ?錯誤提示'os/base_private.h' file not found
解決 ?添加base_private.h文件到os目錄下
問題6 ?錯誤提示'pthread/tsd_private.h' file not found
解決 ?創建pthread文件夾,添加tsd_private.h文件到pthread目錄下
問題7 ?錯誤提示'System/machine/cpu_capabilities.h' file not found
解決 ?創建Syetem文件夾,在System目錄下創建machine文件夾,添加machine/cpu_capabilities.h文件到machine目錄下
問題8 ?錯誤提示'os/tsd.h' file not found
解決 ?添加tsd.h文件到os目錄下
問題9 ?錯誤提示'pthread/spinlock_private.h' file not found
解決 ?添加spinlock_private.h文件到pthread目錄下
問題10 ?錯誤提示'System/pthread_machdep.h' file not found
解決 添加pthread_machdep.h文件
問題11 ?錯誤提示Typedef redefinition with different types ('int' vs 'volatile OSSpinLock' (aka 'volatile int’))
解決 redefinition重定義錯誤時,終端進入Common文件夾,輸入grep -rne "typedef.*pthread_lock_t” .?可以看到所有定義文件
可以看到有2處定義了 pthread_lock_t,注釋掉pthread_machdep.h中的即可
問題12 ?錯誤提示 ?Static declaration of '_pthread_getspecific_direct' follows non-static declaration?
解決 ?可以看到有3個函數重復定義了,這里的話把pthread_machdep.h中這3個函數都注釋掉_pthread_has_direct_tsd(void)、
_pthread_getspecific_direct(unsigned long slot)、
_pthread_setspecific_direct(unsigned long slot, void * val)
問題13 ?錯誤提示'CrashReporterClient.h' file not found
解決 添加CrashReporterClient.h文件到Common路徑下,如果重新編譯還是報這個錯誤的話,需要在項目工程里設置Build Settings->Preprocessor Macros中加入:LIBC_NO_LIBCRASHREPORTERCLIENT
問題14 ?錯誤提示?'Block_private.h' file not found?
解決 ?添加./libdispatch-1008.220.2/src/BlocksRuntime/Block_private.h文件到Common目錄下
問題15 ?錯誤提示'objc-shared-cache.h' file not found
解決 ?添加objc-shared-cache.h文件打Common目錄下
問題16
解決 ?刪除bridgeos(3.0)
問題17 ?錯誤提示'isa.h' file not found
解決 ?isa.h文件在項目目錄下的runtime文件夾中,把isa.h文件加到Common目錄下
問題18 ?錯誤提示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
問題19 ?錯誤提示?'_simple.h' file not found
解決 添加./libplatform-177.200.16/private/_simple.h文件到Common路徑下
問題20 ?錯誤提示?Use of undeclared identifier?‘CRGetCrashLogMessage'
解決需要在項目工程里設置Build Settings->Preprocessor Macros中加入:LIBC_NO_LIBCRASHREPORTERCLIENT
問題21 ?錯誤提示?ld: can't open order file: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/AppleInternal/OrderFiles/libobjc.order
?? ?clang: error: linker command failed with exit code 1 (use -v to see invocation)
解決 更改工程配置: Build Settings->Linking->Order File,改成$(SRCROOT)/libobjc.order
問題22 ?錯誤提示?ld: library not found for -lCrashReporterClient
clang: error: linker command failed with exit code 1 (use -v to see invocation)
解決 ?在 Build Settings -> Linking -> Other Linker Flags里刪掉"-lCrashReporterClient"(Debug和Release都刪了)
問題23 ?錯誤提示提示SDK "macosx.internal" cannot be located.和unable to find utility "clang++", not a developer tool or in PATH
把Target-objc的Build Phases->Run Script(markgc)里的內容macosx.internal改為macosx
問題24 ?錯誤提示no such public header file: '/tmp/objc.dst/usr/include/objc/ObjectiveC.apinotes’
解決把Target-objc的Build Settings->Other Text-Based InstallAPI Flags里的內容設為空,把Text-Based InstallAPI Verification Model里的值改為Errors Only
到這里差不多項目就已經可以編譯成功了!
GC來了,現在就可以創建自己的項目了,然后添加objc依賴,接下來就可以添加測試代碼,斷點調試了。
自己手動編譯技巧:
當缺少那個頭文件時,google一下,就可以知道該文件在哪個開源項目里面,然后把項目下載下來,找到對應的頭文件,加入到自己項目里面就可以了,至于其它錯誤,也是可以google到答案的。
推薦想學習objc底層源碼的,自己可以去配置下源碼。