環(huán)境
- macOS 11.6
- Xcode 13.2.1
- objc4-818.2.tar.gz
編譯錯(cuò)誤處理
1. unable to find sdk 'macosx.internal' (in target 'xxx')
progect -> objc -> Build Settings -> Base SDK -> macOS
- 修改
Run Script (markgc)
腳本中的macosx.internal
為macosx
2.'sys/reason.h' file not found' file not found
- 下載reason.h地址
- 在objc4-818.2目錄下創(chuàng)建文件夾
HZCommon
,并在里面創(chuàng)建文件夾sys
骚烧,然后將下載的reason.h
拷貝到里面 -
target -> objc -> Build Settings - > Header Search Paths
中 添加$(SRCROOT)/HZCommon
3. 'os/feature_private.h' file not found
- 注釋掉這個(gè)頭文件, private一般為私有文件
- 同時(shí) obj-runtime.mm文件中的 os_feature_enabled_simple調(diào)用注釋掉
4. __APPLE_BLEACH_SDK__
Expected function body after function declarator
注釋
#ifndef __APPLE_BLEACH_SDK__
__BRIDGEOS_DEPRECATED(2.0, 2.0, "not recommended")
#endif
類似判斷代碼
5. 'mach-o/dyld_priv.h' file not found
- 下載dyld_priv.h地址
-
HZCommon
中創(chuàng)建文件夾mach-o
朗鸠,然后將下載的dyld_priv.h
拷貝到里面 -
dyld_priv.h
中的, bridgeos(3.0)
全部刪掉
6. 'os/base_private.h'/'os/lock_private.h'/'os/tsd.h' file not found file not found
- 下載base_private.h地址
- 下載lock_private.h地址
- 下載tsd.h地址
-
HZCommon
中創(chuàng)建文件夾os
,然后將下載的base_private.h
,lock_private.h
和tsd.h
拷貝到里面 -
bridgeos(4.0)
刪掉
7. 'pthread/tsd_private.h' file not found
- 下載spinlock_private.h地址
- 下載tsd_private.h地址
-
HZCommon
中創(chuàng)建文件夾pthread
搏予,然后將下載的spinlock_private.h
和tsd_private.h
拷貝到里面
8. 'System/machine/cpu_capabilities.h' file not found
- 下載cpu_capabilities.h地址
-
HZCommon
中創(chuàng)建文件夾System/machine
,然后將下載的cpu_capabilities.h
拷貝到里面
9. 'System/pthread_machdep.h' file not found
- 下載pthread_machdep.h地址
- 將下載的
pthread_machdep.h
拷貝到HZCommon
中的文件夾System
里面
10. 'CrashReporterClient.h' file not found
- 下載CrashReporterClient.h地址
- 在
target -> Build Setting -> Preprocessor Macros
中加入LIBC_NO_LIBCRASHREPORTERCLIENT
11. __BRIDGEOS_UNAVAILABLE
注釋
12. 'Typedef redefinition with different types ('int' vs 'volatile OSSpinLock' (aka 'volatile int'))
可以看見(jiàn)有兩處定義了pthread_lock_t激捏,注釋掉pthread_machdep.h文件中的定義即可鸿竖。
// 如 重復(fù)定義 pthread_lock_t
grep -rne "typedef.*pthread_lock_t” .
// 輸出
./pthread/spinlock_private.h:59:typedef volatile OSSpinLock pthread_lock_t __deprecated_msg("Use <os/lock.h> instead”);
./System/pthread_machdep.h:214:typedef int pthread_lock_t;
13. Static declaration of '_pthread_has_direct_tsd' follows non-static declaration
三個(gè)函數(shù)定義重復(fù)了:
- _pthread_has_direct_tsd(void)
- _pthread_getspecific_direct(unsigned long slot)
- _pthread_setspecific_direct(unsigned long slot, void * val)
pthread_machdep.h文件中的定義注釋掉
14. Mismatch in debug-ness macros
注釋
15. 'objc-bp-assist.h' file not found
- 注釋
- 注釋代碼
if (!dyld_program_sdk_at_least(dyld_platform_version_macOS_10_13)) {
DisableInitializeForkSafety = true;
if (PrintInitializing) {
_objc_inform("INITIALIZE: disabling +initialize fork "
"safety enforcement because the app is "
"too old.)");
}
}
16. 'objc-shared-cache.h' file not found
- 下載objc-shared-cache.h地址
- 將下載的
objc-shared-cache.h
拷貝到HZCommon
里面
17. Use of undeclared identifier 'dyld_fall_2020_os_versions'
注釋
18. '_simple.h' file not found
- 下載_simple.h地址
- 將下載的
_simple.h
拷貝到HZCommon
里面
19. 'Block_private.h' file not found
- 下載Block_private.h地址
- 將下載的
Block_private.h
拷貝到HZCommon
里面
20. 'Cambria/Traps.h' file not found
- 注釋
#include <Cambria/Traps.h>
和#include <Cambria/Cambria.h>
- 注釋代碼
//#if TARGET_OS_OSX
// if (oah_is_current_process_translated()) {
// kern_return_t ret = objc_thread_get_rip(threads[count], (uint64_t*)&pc);
// if (ret != KERN_SUCCESS) {
// pc = PC_SENTINEL;
// }
// } else {
// pc = _get_pc_for_thread (threads[count]);
// }
//#else
pc = _get_pc_for_thread (threads[count]); // 需要保留
//#endif
21. 'os/linker_set.h' file not found
- 注釋
#include <os/linker_set.h>
- 注釋代碼
// LINKER_SET_FOREACH(_dupi, const objc_duplicate_class **, "__objc_dupclass") {
// const objc_duplicate_class *dupi = *_dupi;
//
// if (strcmp(dupi->name, name) == 0) {
// return;
// }
// }
22. 'kern/restartable.h' file not found
- 下載restartable.h地址
- 在
HZCommon
中創(chuàng)建文件夾kern
- 將下載的
restartable.h
拷貝到HZCommon
中的kern
文件夾
23. 'os/feature_private.h' file not found
- 注釋
#include <os/feature_private.h>
24. 'os/reason_private.h' file not found
和'os/variant_private' file not found
- 注釋引入
- 注釋代碼
// if (DebugPoolAllocation || sdkIsAtLeast(10_12, 10_0, 10_0, 3_0, 2_0)) {
// // OBJC_DEBUG_POOL_ALLOCATION or new SDK. Bad pop is fatal.
// _objc_fatal
// ("Invalid or prematurely-freed autorelease pool %p.", token);
// }
25. '_static_assert' declared as an array with a negative size
//STATIC_ASSERT((~ISA_MASK & MACH_VM_MAX_ADDRESS) == 0 ||
// ISA_MASK + sizeof(void*) == MACH_VM_MAX_ADDRESS);
26. Use of undeclared identifier 'dyld_fall_2018_os_versions'
// if (!DisableTaggedPointerObfuscation && dyld_program_sdk_at_least(dyld_fall_2018_os_versions)) {
if (!DisableTaggedPointerObfuscation) {
27. 路徑問(wèn)題ld: can't open order file: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/AppleInternal/OrderFiles/libobjc.order
target -> Build Setting -> Linking -> Order File -> $(SRCROOT)/libobjc.order
28. library not found for -lCrashReporterClient
target -> Build Setting -> Other Linker Flags -> Any macOS SDK -> -lCrashReporterClient
刪除掉
29 library not found for -loah
target -> Build Setting -> Other Linker Flags -> Any macOS SDK -> -loah
刪除掉
30 library doesn't have symbol '***'
?圆凰?杈帐?
之前修改配置的時(shí)候,改錯(cuò)了東西
建議重走一遍
踩完上面的坑,基本會(huì)Build Success
了
最后可以新建一個(gè)target關(guān)聯(lián)objc挑童,就可以愉快的探索底層了
不建議直接下載已經(jīng)可以編譯工程直接運(yùn)行累铅,會(huì)減少很多樂(lè)趣與痛苦
參考文章
objc源碼編譯
OC底層探索01:objc-781 源碼調(diào)試和編譯
objc4-818.2編譯踩坑總結(jié)篇