objc4-818.2配置編譯

環(huán)境

編譯錯(cuò)誤處理

1. unable to find sdk 'macosx.internal' (in target 'xxx')

  • progect -> objc -> Build Settings -> Base SDK -> macOS
  • 修改Run Script (markgc)腳本中的macosx.internalmacosx

2.'sys/reason.h' file not found' file not found

  1. 下載reason.h地址
  2. 在objc4-818.2目錄下創(chuàng)建文件夾HZCommon,并在里面創(chuàng)建文件夾sys,然后將下載的reason.h拷貝到里面
  3. 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

  1. 下載dyld_priv.h地址
  2. HZCommon中創(chuàng)建文件夾mach-o,然后將下載的dyld_priv.h拷貝到里面
  3. dyld_priv.h中的, bridgeos(3.0)全部刪掉

6. 'os/base_private.h'/'os/lock_private.h'/'os/tsd.h' file not found file not found

  1. 下載base_private.h地址
  2. 下載lock_private.h地址
  3. 下載tsd.h地址
  4. HZCommon中創(chuàng)建文件夾os,然后將下載的base_private.h,lock_private.htsd.h拷貝到里面
  5. bridgeos(4.0)刪掉

7. 'pthread/tsd_private.h' file not found

  1. 下載spinlock_private.h地址
  2. 下載tsd_private.h地址
  3. HZCommon中創(chuàng)建文件夾pthread,然后將下載的spinlock_private.htsd_private.h拷貝到里面

8. 'System/machine/cpu_capabilities.h' file not found

  1. 下載cpu_capabilities.h地址
  2. HZCommon中創(chuàng)建文件夾System/machine,然后將下載的cpu_capabilities.h拷貝到里面

9. 'System/pthread_machdep.h' file not found

  1. 下載pthread_machdep.h地址
  2. 將下載的pthread_machdep.h拷貝到HZCommon中的文件夾System里面

10. 'CrashReporterClient.h' file not found

  1. 下載CrashReporterClient.h地址
  2. target -> Build Setting -> Preprocessor Macros中加入LIBC_NO_LIBCRASHREPORTERCLIENT

11. __BRIDGEOS_UNAVAILABLE

注釋

12. 'Typedef redefinition with different types ('int' vs 'volatile OSSpinLock' (aka 'volatile int'))

可以看見有兩處定義了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

  1. 注釋
  2. 注釋代碼
 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

  1. 下載objc-shared-cache.h地址
  2. 將下載的objc-shared-cache.h拷貝到HZCommon里面

17. Use of undeclared identifier 'dyld_fall_2020_os_versions'

注釋

18. '_simple.h' file not found

  1. 下載_simple.h地址
  2. 將下載的_simple.h拷貝到HZCommon里面

19. 'Block_private.h' file not found

  1. 下載Block_private.h地址
  2. 將下載的Block_private.h拷貝到HZCommon里面

20. 'Cambria/Traps.h' file not found

  1. 注釋#include <Cambria/Traps.h>#include <Cambria/Cambria.h>
  2. 注釋代碼
//#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

  1. 注釋#include <os/linker_set.h>
  2. 注釋代碼
//    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

  1. 下載restartable.h地址
  2. HZCommon中創(chuàng)建文件夾kern
  3. 將下載的restartable.h拷貝到HZCommon中的kern文件夾

23. 'os/feature_private.h' file not found

  1. 注釋#include <os/feature_private.h>

24. 'os/reason_private.h' file not found'os/variant_private' file not found

  1. 注釋引入
  2. 注釋代碼
//        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. 路徑問題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ì)減少很多樂趣與痛苦

參考文章

objc源碼編譯
OC底層探索01:objc-781 源碼調(diào)試和編譯
objc4-818.2編譯踩坑總結(jié)篇

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容