objc4-818.2配置编译

环境

  • macOS 11.6
  • Xcode 13.2.1
  • objc4-818.2.tar.gz

编译错误处理

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目录下创建文件夹HZCommon,并在里面创建文件夹sys,然后将下载的reason.h拷贝到里面
  3. target -> objc -> Build Settings - > Header Search Paths中 添加$(SRCROOT)/HZCommon

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

  • 注释掉这个头文件, private一般为私有文件
  • 同时 obj-runtime.mm文件中的 os_feature_enabled_simple调用注释掉

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中创建文件夹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中创建文件夹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中创建文件夹pthread,然后将下载的spinlock_private.htsd_private.h拷贝到里面

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

  1. 下载cpu_capabilities.h地址
  2. HZCommon中创建文件夹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文件中的定义即可。

// 如 重复定义 pthread_lock_t
grep -rne "typedef.*pthread_lock_t” .
// 输出
./pthread/spinlock_private.h:59:typedef volatile OSSpinLock pthread_lock_t __deprecated_msg("Use  instead”);
./System/pthread_machdep.h:214:typedef int pthread_lock_t;

13. Static declaration of '_pthread_has_direct_tsd' follows non-static declaration

三个函数定义重复了:

  • _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 #include
  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
  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中创建文件夹kern
  3. 将下载的restartable.h拷贝到HZCommon中的kern文件夹

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

  1. 注释#include

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 '***' ???

之前修改配置的时候,改错了东西

建议重走一遍

踩完上面的坑,基本会Build Success

最后可以新建一个target关联objc,就可以愉快的探索底层了

不建议直接下载已经可以编译工程直接运行,会减少很多乐趣与痛苦

参考文章

objc源码编译
OC底层探索01:objc-781 源码调试和编译
objc4-818.2编译踩坑总结篇

你可能感兴趣的:(objc4-818.2配置编译)