一、准备工作
- mac OS 10.15.4 (博主当前mac版本演示)
- Xocde 11.7
- objc4-781.2
二、objc4-787源码下载
- 进入苹果opnesource官网
- 下载objc4-781.2
-
进入mac10.15.3
image.png
-
搜索objc
image.png
三、打开工程(objc4-787.1)
-
选择 objc-simulator 运行
image.png
四、解决报错
错误一:unable to find sdk 'macosx.internal'
-
Bulid Settings -> Architecures -> Base SDK -> 修改成 macOS 10.15
image.png
- targets -> objc -> Bulid Phases -> Run Script(markgc) -> macosx.internal 改成 macosx
错误二:文件查漏补缺
如:'sys/reason.h' file not found
- 大家可以通过 Apple source 在
xnu-xxx/bsd/sys/reason.h路径自行下载 - 还可以通过谷歌中输入reason.h site:opensource.apple.com 定向检索
拿到.h文件后加入到工程里面。
-
在根目录创建一个
include文件夹 -
创建
sys文件 -
把
reason.h文件加进去
image.png
-
加入之后还需要配置工程的文件路径
-
选择 target -> objc -> Build Settings
-
在工程的 Header Serach Paths 中添加搜索路径 $(SRCROOT)/include
image.png
//: 后面的头文件报错都这样处理
'mach-o/dyld_priv.h' file not found
'os/lock_private.h' file not found
'os/base_private.h' file not found
'pthread/tsd_private.h' file not found
'System/machine/cpu_capabilities.h' file not found
'os/tsd.h' file not found
'pthread/spinlock_private.h' file not found
'System/pthread_machdep.h' file not found
'CrashReporterClient.h' file not found
'objc-shared-cache.h' file not found
'_simple.h' file not found
'Block_private.h' file not found
'kern/restartable.h' file not found
image.png
错误三:
ld: can't open order file: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/AppleInternal/OrderFiles/libobjc.order
- 设置Targets -> Build Settings -> Order files debug为:$(SRCROOT)/libobjc.order
错误四:我们如果直接导入 Apple source 下载的
CrashReporterClient还是会报错:'CrashReporterClient.h' file not found
- 需要在 Build Settings -> Preprocessor Macros 中加入:LIBC_NO_LIBCRASHREPORTERCLIENT
错误五:Use of undeclared identifier ‘DYLD_MACOSX_VERSION_10_13
- 在 dyld_priv.h 文件顶部加入以下宏:
#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
错误六:
ld: library not found for -lCrashReporterClient
- 删除Targets -> Build Settings -> other Linker Flager 中的
-lCrashReporterClient
四、编译成功
- 出现 Build Succeeded
五、objc编译调试
-
新建一个 Target : GomuTest
image.png
-
绑定二进制依赖关系
image.png
- 运行代码进入源码,大家可以自由编译调试咯!
编译的时候遇到main里面下断点不走的问题
- Targets -> GomuTest -> Build Phases -> Compile Sources 中,把
main.m放在第一位
image.png













网友评论