iOS底层-2:objc4 779.1源码编译调试

环境:
macOS : 10.15.4
Xcode: 11.1
objc4: 779.1(objc4下载)

其他需要的库:


image.png

大家可以前往苹果开源网址下载。其中launchd-106.3是在macOS10.4.4下载的,其他都是在macOS10.15.5里下载的。

开始配置

下载的objc4_779.1的代码,直接编译会报如下错误


image.png

unable to find sdk 'macosx.internal'

Targets --> Build Setting --> Base SDK 中将macosx.internal 改为 macOS

image.png

编译出现如下错误


image.png

’sys/reason.h‘ file not found

大家可以通过 Apple source 在 xnu-6153.121.1/bsd/sys/reason.h 路径自行下载

把找到的文件拖入工程:

  • 我在根目录下创建一个LRCommon文件夹
  • 创建sys文件
  • 拖入reason.h
image.png

还没完,在工程的 Header Serach Paths 中添加搜索路径 $(SRCROOT)/LRCommon

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
'kern/restartable.h' file not found
'Block_private.h' file not found

上面报错的解决方式和’sys/reason.h‘ file not found是一样的,添加完成如下图

image.png

CrashReporterClient异常

直接导入Apple open source下载的CrashReporterClient.h文件还是会报错

'CrashReporterClient.h' file not found

  • 解决

Build Settings -> Preprocessor Macros 中加入:LIBC_NO_LIBCRASHREPORTERCLIENT

libobjc.order 路径问题

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
image.png
lCrashReporterClient 编译不到

Library not found for -lCrashReporterClient

  • 选择 target -> objc -> Build Settings
  • Other Linker Flags 中删除 -lCrashReporterClient ( DebugRelease 都删了)
image.png
Xcode 脚本编译问题

/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
image.png
编译成功

到这里编译成功 -Build Succeeded!,还是很开心的。

objc编译调试
  • 新建一个Target
    File -> New -> Target

    image.png

  • 绑定二进制依赖关系


    image.png
  • 运行代码进入源码,可以自由调试了


    image.png

完整版链接: https://pan.baidu.com/s/1HAB8gK9snqwmk5c6mQMObQ 密码: oq3h

你可能感兴趣的:(iOS底层-2:objc4 779.1源码编译调试)