Objc4-750源码编译

2020-03-06  本文已影响0人  江南易飞

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源码编译

上一篇下一篇

猜你喜欢

热点阅读