Objc4-750源码编译

objc4源码编译

我们都知道在编写IOS代码的时候,都会将我们编写的diamante转换成Runtime运行时。比如我上一篇介绍了消息转发机制提到的调用的方法都会执行objc_msgSend()。下面我们来看一下苹果开源的源码的底层实现。

可以从下面这个链接下载objc4源码
苹果开源源码

我们也可以打开 https://opensource.apple.com/tarballs/查看相关源码和依赖库
我们可以看到,源码后面跟着版本号如:objc4-750.tar.gz ,毋庸置疑,版本号越高说明就是越新的。

下载objc4相关依赖

如果想要成功编译objc4,还需要下载相关依赖库文件:libc, dyld, libauto, libclosure, libdispatch, libpthread, xun,launchd, 这些库都在上述链接可以找到,下载最新的即可。
如果不想下载,可以进入任意门下载[https://github.com/S-Freedom/objc-runtime]

编译常见问题

1)error: The i386 architecture is deprecated. You should update your ARCHS build setting to remove the i386 architecture. (in target 'objc')
解决:找target对应编译设置(Build Settings)->CPU架构(Architecture)->标准(Standard arcgutectures)

2)在objc-os.h头文件中报'sys/reason.h' file not found错误
解决:工程目录下创建include/sys目录,在编译设置(Build Settings里面搜索,Header Search Paths,然后将include索引添加进去),然后在之前下载的依赖包中搜索reason.h头文件,复制到include/sys目录下

3)在objc-os.h头文件中报'mach-o/dyld_priv.h' file not found错误
解决:同上一步,创建include/mach-o目录,复制dyld_priv.h头文件到相应目录

4)在objc-os.h头文件中报'os/lock_private.h' file not found错误
解决:这个文件并没有再我们下载的依赖库中,需要去开源官网下载,然后操作同上一步

5)以下是遇到的类似问题:
'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;(这个需要在编译设置(Build Settings添加宏变量Build Settings->Preprocessor Macros中加入:LIBC_NO_LIBCRASHREPORTERCLIENT)
'Block_private.h' file not found;
'objc-shared-cache.h' file not found;
'isa.h' file not found;
'_simple.h' file not found;
在objc-errors.mm文件中报:Use of undeclared identifier 'CRGetCrashLogMessage'错误;

6)链接时候错误:
ld: can't open order file: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/AppleInternal/OrderFiles/libobjc.order
clang: error: linker command failed with exit code 1 (use -v to see invocation)
解决:将Build Settings->Linking->Order File改为工程根目录下的libobjc.order,即:$(SRCROOT)/libobjc.order。

7)编译脚本错误
xcodebuild: error: SDK "macosx.internal" cannot be located.
xcrun: error: unable to find utility "clang++", not a developer tool or in PATH
解决:把Target-objc的Build Phases->Run Script(markgc)里的内容macosx.internal改为macosx,这里猜测macosx.internal为苹果内部的macosx

8)error: no such public header file: '/tmp/objc.dst/usr/include/objc/ObjectiveC.apinotes'错误
解决:把Text-Based InstallAPI Verification Model里的值改为Errors Only,把Support Text-Based InstallAPI设置成NO

  1. error: library not found -lCrashReporterClient.h 建议把这个文件以及下面的配置删掉 macos CrashReporterClient.h,改成一下配置

编译成功

解决以上错误后,不出意外应该是build success.

创建自己的项目,debug最新的的源码

现在你就可以新建项目,为了方便起见,创建了command line tool

以上摘自
Runtime源码编译

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • OC的一个主要特性Runtime运行时特性,在日常开发中我们使用到的都是不可见的,还好官方提供了Runtime(o...
    yahibo阅读 5,268评论 7 6
  • 最新版本的Runtime源码已经出来了,是不急不可耐的想用用它呢?在这里我将一步步教大家如何编译它,首先贴个自己的...
    逆风g阅读 7,140评论 1 10
  • 最新版本的Runtime源码已经出来了,是不急不可耐的想用用它呢?在这里我将一步步教大家如何编译它,首先贴个自己的...
    Cooci_和谐学习_不急不躁阅读 9,195评论 8 19
  • 环境 macOS 10.14.1 Xcode 10.3 objc4-750.1 下载源码以及相关依赖 在MacOS...
    测试开发雨辰阅读 2,299评论 0 0
  • 目前objc4最新的源码是750.1版本,看网上也没人写了这个版本的编译方法,所以这里记录一下。编译方法都大同小异...
    政在coding阅读 4,770评论 1 1

友情链接更多精彩内容