objc源码编译

2021-06-08  本文已影响0人  HotPotCat

一、环境配置

依赖项目

所有的源码都可以在opensource中找到。

二、配置

首先选中objc target进行编译。

  1. unable to find sdk 'macosx.internal'
    image.png
    修改脚本macosx.internalmacosx
    image.png

并且修改basesdkmacOS

image.png

2.'sys/reason.h' file not found
在项目根目录创建自己的文件夹,我这来是HPCommon,将xnu中的bsd/sys目录中的sys/reason.h文件拷贝到这个目录中:

image.png
配置Search Header
image.png
同理:
错误 目录
'mach-o/dyld_priv.h' file not found dyld include/mach-o
'os/lock_private.h' file not found libplatform os/lock_private.h
'os/base_private.h' file not found xnu os/base_private.h
'pthread/tsd_private.h' file not found libpthread pthread/tsd_private.h
'System/machine/cpu_capabilities.h' file not found xnu System/machine/cpu_capabilities.hosfmk/machine/目录下的)
'os/tsd.h' file not found xnu os/tsd.h
'pthread/spinlock_private.h' file not found libpthread pthread/spinlock_private.h
'System/pthread_machdep.h' file not found libc System/pthread_machdep.hlibc新版本中没有找打,老版本有
'CrashReporterClient.h' file not found libc CrashReporterClient.h'libc新版本中没有找打,老版本有
'os/linker_set.h' file not found Libc os/linker_set.h
'Cambria/Traps.h' file not found xnu Cambria/Traps.h
'_simple.h' file not found libplatform _simple.h
'Cambria/Cambria.h' file not found 注释掉
'kern/restartable.h' file not found xnu kern/restartable.h
'os/feature_private.h' file not found 注释
objc-bp-assist.h' file not found 注释
'objc-shared-cache.h' file not found dyld objc-shared-cache.h
'os/feature_private.h' file not found 注释
'os/reason_private.h' file not found 注释
'os/variant_private.h' file not found 注释
'Block_private.h' file not found libclourse Block_private.h

还需要增加LIBC_NO_LIBCRASHREPORTERCLIENT宏定义:

image.png

3.Expected ','

image.png
注释掉bridgeos相关内容:
image.png

4.Use of undeclared identifier 'dyld_platform_version_macOS_10_11'

image.png
直接注释掉。

5.Use of undeclared identifier 'oah_is_current_process_translated'

image.png
直接注释
  1. Use of undeclared identifier 'dyld_fall_2020_os_versions'
    image.png
    注释

7.Use of undeclared identifier 'objc4'

image.png
注释

8.'_static_assert' declared as an array with a negative size

image.png
注释

9.Use of undeclared identifier 'dyld_platform_version_macOS_10_13'

image.png
注释

10.Use of undeclared identifier 'dyld_fall_2018_os_versions'

image.png

修改

11.Use of undeclared identifier 'dyld_platform_version_bridgeOS_2_0'

image.png
注释
  1. libobjc.order 路径问题
    can't open order file: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/AppleInternal/OrderFiles/libobjc.order

    image.png
  2. library not found for -lCrashReporterClient

    image.png
    releasedebug都删除。

14.library not found for -loah

image.png
删除-loah

这个时候一般能正常编译通过了。

三、编译调试

  1. 新建一个macOS commandLine TargetHPObjcTest

    image.png
  2. 绑定二进制依赖关系


    image.png
  3. 运行进行源码调试


    image.png
    image.png

    这个时候断点能够进入,就大功告成。

总结:
如果自己的Target编译调试遇见问题,尝试以下配置:
1: enable hardened runtime -> NO
2: build phase -> denpendenice -> objc
3: 如果main函数中断点断不住,尝试重新创建自己的Targetmain放在Compile Sources最前面。

image.png

可以直接下载我编译好的进行调试objc4-818.2编译好的源码
参考:
https://juejin.cn/post/6844903959161733133

上一篇下一篇

猜你喜欢

热点阅读