报错29:'os/variant_private.h' file not found
同样是文件缺失,variant_private.h这个文件在
Libc-1439.141.1/os/目录下
解决方式:
- 将variant_private.h从Libc-1439.141.1/os/目录下copy到JQDependencies/os/目录下
报错30:Use of undeclared identifier 'dyld_platform_version_bridgeOS_2_0'
解决方式:
- 注释掉这5行代码
报错31:/os/variant_private.h:243:75: Expected ','
解决方式:
- 删除bridgeos这个参数
报错32:** '_static_assert' declared as an array with a negative size**
解决方式:
- 注释掉这两行代码
报错33:Can't open order file: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/AppleInternal/OrderFiles/libobjc.order
解决方式:
- target -> objc -> Build Settings,在工程的Order File中添加搜索路径$(SRCROOT)/libobjc.order
报错34:Library not found for -lCrashReporterClient
没有找到CrashReporterClient这个Library库,
解决方式:
- target -> objc -> Build Settings,在工程的Other Link Flags中删除-lCrashReporterClient
报错35:Library not found for -loah
和报错34类似,没有找到 oah 这个Library库
解决方式:
- target -> objc -> Build Settings,在工程的Other Link Flags中删除-loah
报错36:xcodebuild:1:1: SDK "macosx.internal" cannot be located.
解决方式:
- 选择 target -> objc -> Build Phases -> Run Script(markgc)
- 把脚本文本macosx.internal改成macosx,和刚开始我们选的base sdk中的macosx对齐
OK!到此处,再次编译,** Build Succeeded**。objc这个源码库终于可以编译成功了!
三、objc源码调试
1. 新建target:JQObjcBuildDemo
2. 给JQObjcBuildDemo添加依赖库
- 选择 target -> JQObjcBuildDemo -> General -> Frameworks and Libraries ,点击"+"添加 libobjc.A.dylib
然后检查一下,依赖库有没有添加进来。选择 target -> objc -> Build Phases,看一下Dependencies和Link Binary With Libraries,如下图一样添加上了,就OK了!(ps: 如果没有添加,这里手动再添加一次。)
3. 调试objc源码
- 将Build Settings中将Enable Hardened Runtime设置为NO,否则在objc源码下的断点没法断住,这个是Xcode 11的新特性。
- 新建JQPerson类
- 在main.m中引入并实例化一个JQPerson
- 编译运行,如图
- 按住command,点击[JQPerson alloc]的alloc,跳转到objc的源码中+ (id)alloc{,在这里打上断点
注意:源码中+ (id)alloc{这个断点要先禁用,等到程序断点断在了JQPerson p = [JQPerson alloc];这一行的时候,再去objc源码中开启+ (id)alloc{*这个方法的断点。否则,项目一运行,会有很多alloc方法断住,一步步执行,你会爆炸的。切记!!!
好了,到此,我们就可以愉快的进行objc的源码调试了,感兴趣的小伙伴赶紧来试试吧!
四、总结
- 项目中缺失的文件可能在你下载的依赖库中找不到,这个时候就要考虑一下去依赖库的新版本或者旧版本中找一下。比如我上面遇到的:'System/pthread_machdep.h'文件只有在Libc-825.40.1及以下版本才有。
- 缺失文件汇总
# 缺失文件名 (对应的依赖库路径) 1. 'sys/reason.h' file not found (xnu-7195.141.2/bsd/sys) 2. 'mach-o/dyld_priv.h' file not found (dyld-852.2/include/mach-o) 3. 'os/lock_private.h' file not found (libplatform-254.80.2/private/os) 4. 'os/base_private.h' file not found (libplatform-254.80.2/private/os) 5. 'pthread/tsd_private.h' file not found (libpthread-libpthread-454.120.2/private/pthread) 6. 'pthread/spinlock_private.h' file not found (libpthread-libpthread-454.120.2/private/pthread) 7. 'System/machine/cpu_capabilities.h' file not found (xnu-7195.141.2/osfmk/machine) 8. 'os/tsd.h' file not found (xnu-7195.141.2/libsyscall/os) 9. 'System/pthread_machdep.h' file not found (Libc-825.40.1/pthreads) 10. 'CrashReporterClient.h' file not found (Libc-825.40.1/include) 11. 'objc-shared-cache.h' file not found (dyld-852.2/include) 12. 'objc-bp-assist.h' file not found 文件的引用注释掉 13. '_simple.h' file not found (libplatform-libplatform-220.100.1/private) 14. 'os/linker_set.h' file not found (xnu-7195.141.2/bsd/sys) 15. 'Cambria/Traps.h' file not found 文件在开源网站找不到 ,文件的引用注释掉 16. 'Block_private.h' file not found (libclosure-79/) 17. 'kern/restartable.h' file not found (xnu-7195.141.2/osfmk/kern/) 18. 'os/feature_private.h' file not found 文件的引用注释掉 19. 'os/reason_private.h' file not found (xnu-7195.141.2/libkern/os/) 20. 'os/variant_private.h' file not found (Libc-1439.141.1/os/)
- 已经完成 objc4-818 源码项目,大家可以直接去GitHub下载:JQObjc4-818.2BuildDebug