iOS-底层原理 02:objc4-781编译环境

2020-09-24  本文已影响0人  没有昵称的昵称没有

本文目的是介绍如何将objc4-781的源码编译成功,然后在源码中进行调试,便于跟踪方法的底层实现流程。

快捷通道,可下载Cooci老师的可编译源码 : 运行objc4-781版本,然后直接看编译探索、调试

编译环境

下载资源

objc4-781下载

依赖文件

需要下载以下依赖文件

依赖文件
苹果开源源码页面,除了lauchd-106.10需要在macOS -> 10.4.4.x86版本中下载。 其余均可在macOS -> 10.15.1版本中搜索到。

源码编译

打开objc.xcodeproj,选中objc target,开始编译。
编译中遇到的问题

问题一:unable to find sdk 'macosx.internal'

问题一

解决方法:

问题二:文件找不到的报错问题

1. 'sys/reason.h' file not found
2. 'mach-o/dyld_priv.h' file not found
#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
3. 'os/lock_private.h' file not found和 'os/base_private.h' file not found
4. 'pthread/tsd_private.h' file not found 和 'pthread/spinlock_private.h' file not found
5. 'System/machine/cpu_capabilities.h' file not found
6. 'os/tsd.h' file not found
7. 'System/pthread_machdep.h' file not found

在最新版的macOS 10.15中最新版下载的libc中没有这个h文件,需要下载Libc-583版本

8. 'CrashReporterClient.h' file not found
9. 'objc-shared-cache.h' file not found
10. Mismatch in debug-ness macros
11. '_simple.h' file not found
12. 'kern/restartable.h' file not found
13. 'Block_private.h' file not found
14. libobjc.order 路径问题

问题描述为:can't open order file: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/AppleInternal/OrderFiles/libobjc.order

15. Xcode 脚本编译问题

问题描述为:/xcodebuild:1:1: SDK "macosx.internal" cannot be located.

到这里应该试一试能否编译成功


编译探索、调试

1. 新建一个target :HWObjc
2. 绑定二进制依赖关系
image.png
3. 自定义一个HWPerson
image.png

4. 创建的调试target中main的断点无法断住的问题

上一篇 下一篇

猜你喜欢

热点阅读