macOS 11.1下objc4-818.2源码编译调试

132 阅读2分钟
  • 前期需要的源码以及文件都能在Apple Open Source下载到
  • 注意⚠️⚠️
  • 下面第九个文件需要在Libc-583下载
  • 下面第十个文件需要在Libc-825.24下载
  1. objc4-818.2
  2. xnu-7195.60.75/bsd/sys/reason.h
  3. dyld-832.7.1/include/mach-o/dyld_priv.h
  4. libplatform-254.60.1/private/os/lock_private.h
  5. libpthread-454.60.1/private/pthread/tsd_private.h
  6. xnu-7195.60.75/osfmk/machine/cpu_capabilities.h
  7. xnu-7195.60.75/libsyscall/os/tsd.h
  8. libpthread-454.60.1/private/pthread/spinlock_private.h
  9. Libc-583/pthreads/pthread_machdep.h
  10. Libc-825.24/include/CrashReporterClient.h
  11. dyld-832.7.1/include/objc-shared-cache.h
  12. libplatform-254.60.1/private/_simple.h
  13. libclosure-78/Block_private.h
  14. xnu-7195.60.75/osfmk/kern/restartable.h
  15. xnu-7195.60.75/libkern/os/base_private.h

首先运行起来会有如下报错 1615172368267.jpg 修改如下图 image.png image.png

选择target->objc-->Build Phases-->Run Script(markgc)把脚本文本macosx.internal改成macosx image.png

前期好的文件如下所示 image.png 接下来是第一个报错如下 image.png

  • 创建一个文件夹Common在工程根目录下,再按如下配置好搜索路径 image.png
  • 把前期下载好的文件按照如下 image.png

还有缺少的文件报错如下

'sys/reason.h' file not found '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

这个os/dyld.priv.hos/lock_private.h文件中报错如下,是因为Bridge OS是Apple独立的T2安全芯片使用的嵌入式操作系统, 而在这里我们用不到这个系统所以删掉,bridgeos(3.0),bridgeos(4.0)即可 image.png

CrashReporterClient.h报错如下,需要在Build Settings -> Preprocessor Macros 中加入:LIBC_NO_LIBCRASHREPORTERCLIENT image.png

需要注释的代码如下 image.png image.png image.png image.png image.png image.png image.png image.png image.png image.png image.png image.png image.png image.png image.png image.png

#接下来是libobjc.order 路径问题

can't open order file:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/AppleInternal/OrderFiles/libobjc.order

  • 选择target->objc->Build Settings
  • 在工程的Order File中添加路径$(SRCROOT)/libobjc.order image.png #lCrashReporterClient 编译不到

library not found for -lCrashReporterClient

  • 选择 target -> objc -> Build Settings
  • Other Linker Flags 中删除 -lCrashReporterClient ( Debug 和 Release 都删了)

image.png

#library not found for -loah

  • 选择 target -> objc -> Build Settings
  • Other Linker Flags 中删除 -loah ( Debug 和 Release 都删了)

image.png

编译成功

objc 编译调试

  • 新建一个 Target : LBTest
  • 绑定二进制依赖关系 image.png #最后注意无法进入到源码断点中,需要完成以下两步
  • 找到LBTest->Build Settings->Enable Hardended Runtime,将其设置为No
  • 确保编译源文件中main.h是第一个 image.png