不少小伙伴在探索底层的时候常常很苦恼,只能靠猜想!稍微灵活一点的小伙伴会经过
Apple
提供的源码来辅助看一下,可是很显然这不太直观!若是可以直接编译调试,像咱们本身的代码直接 LLDB 调试,流程跟踪。那简直不要太爽,因而我编译了如今最新的iOS_objc4-756.2
git
若是想先来体验一把的小伙伴能够直接 GitHub 源码 下载!github
若是你也想亲自体验一把,请你准备条件:macos
以上资料均可以在 Apple source 获取到。api
首先你下载的iOS_objc4-756.2
直接编译会报错以下:xcode
Showing Recent Messages The i386 architecture is deprecated. You should update your ARCHS build setting to remove the i386 architecture.架构
解决: 将
objc
和objc-trampolines
中的Build Settings
选项Architectures
中的值切换为Standard Architectures(64-bit Intel)
app
'sys/reason.h' file not foundide
这个资料我已经给你们找好了:学习
objc-756.2编译资料/xnu-4903.241.1/bsd/sys/reason.h
xnu-4903.241.1/bsd/sys/reason.h
路径自行下载reason.h site:opensource.apple.com
定向检索把找到的文件加入到工程里面。例如:ui
KCCommon
文件sys
文件reason.h
文件加入进去目前还不行,必定给咱们的工程设置文件检索路径
target
-> objc
-> Build Settings
Header Serach Paths
中添加搜索路径 $(SRCROOT)/KCCommon
'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
上面的报错状况处理方式都是和 'sys/reason.h' file not found
同样的解决
文件补漏状况以下图:
咱们若是直接导入 Apple source 下载的 CrashReporterClient
仍是会报错:
'CrashReporterClient.h' file not found
解决:
Build Settings
-> Preprocessor Macros
中加入:LIBC_NO_LIBCRASHREPORTERCLIENT
CrashReporterClient
,这里面咱们直接更改了里面的宏信息 #define LIBC_NO_LIBCRASHREPORTERCLIENT
GitHub 源码 这是修改过的!下面板书我修改了什么
报错: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
复制代码
Can't open order file: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/AppleInternal/OrderFiles/libobjc.order
target
-> objc
-> Build Settings
Order File
中添加搜索路径 $(SRCROOT)/libobjc.order
Library not found for -lCrashReporterClient
target
-> objc
-> Build Settings
Other Linker Flags
中删除 -lCrashReporterClient
( Debug
和 Release
都删了)Undefined symbol: _objc_opt_class
这个问题是由于要适配新系统:MacOS 10.15, 由于如今笔者写这一篇文章的时候,尚未正式版本推送!这里咱们向下兼容 MacOS 10.14
/xcodebuild:1:1: SDK "macosx.internal" cannot be located.
/xcrun:1:1: sh -c '/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -sdk macosx.internal -find clang++ 2> /dev/null' failed with exit code 16384: (null) (errno=No such file or directory)
/xcrun:1:1: unable to find utility "clang++", not a developer tool or in PATH
target
-> objc
-> Build Phases
-> Run Script(markgc)
macosx.internal
改为 macosx
no such public header file: '/tmp/objc.dst/usr/include/objc/ObjectiveC.apinotes'
target
-> objc
-> Build Settings
Text-Based InstallAPI Verification Model
中添加搜索路径 Errors Only
Other Text-Based InstallAPI Flags
清空全部内容接下来你能够编译 - Build Succeeded
- 恭喜你!💐
可能到这里你已经老血吐了一地了!的确配置过程仍是相对来讲有点恶心,尤为是文件的查漏补缺,可是咱们享受编译成功的喜悦吧!
Target
: LGTestiOS 如今更多的会偏向底层开发研究,可调式编译的 objc4 源码
可以帮助更快速学习和更容易理解!博客持续更新中,谢谢你们的关注点赞!Thanks♪(・ω・)ノ