iOS object818.2源码编译心路历程

iOS object818.2源码编译心路历程

编译环境 MacOS11.3.1
Xcode版本12.5

首先找到苹果源码地址
找到objc源码
下载一个版本下来,我下载的是objc4-818.2.tar.gz 解压后如下图
在这里插入图片描述
运行了一下发现报错 oh 这不是我想要的结果
在这里插入图片描述
这是Xcode12.5的锅吗 伤心
Build Settings -> Base SDK -> macOS
报错解决了
可是又出新的错误了
在这里插入图片描述
还真是不容易啊
接着解决错误
通过谷歌中输入reason.h site:opensource.apple.com 定向检索
下载
把找到的文件加入到工程里面。例如:
我在根目录创建了一个 OBJCCommon 文件
创建 sys 文件
把 reason.h 文件加入进去
在这里插入图片描述
接下来就是设置路径,文件的检索路劲
选择 target -> objc -> Build Settings
在工程的 Header Serach Paths 中添加搜索路径 $(SRCROOT)/OBJCCommon
在这里插入图片描述
下面这些找不到的 可以按照reason.h的方式 去搜索下载
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

补齐后如下图所示
在这里插入图片描述

接着又发现一个错误CrashReporterClient没有找到,有点心累了
直接导入 Apple source 下载的 CrashReporterClient 还是会报错
在这里插入图片描述
还是得沉住气来解决这个问题:
需要在 Build Settings -> Preprocessor Macros 中加入:LIBC_NO_LIBCRASHREPORTERCLIENT
接着又发现os/feature_private.h 没有找到
心累的边缘不断徘徊
注释掉//#include <os/feature_private.h>
接着还是报错
接着注释
// if (!dyld_program_sdk_at_least(dyld_fall_2020_os_versions))
// DisableAutoreleaseCoalescingLRU = true;

// if (!os_feature_enabled_simple(objc4, preoptimizedCaches, true)) {
// DisablePreoptCaches = true;
// }

编译还是报错 那接着注释
//#include “objc-bp-assist.h”

// if (!dyld_program_sdk_at_least(dyld_platform_version_macOS_10_13)) {
// DisableInitializeForkSafety = true;
// if (PrintInitializing) {
// _objc_inform("INITIALIZE: disabling +initialize fork "
// "safety enforcement because the app is "
// “too old.)”);
// }
// }

static void
initializeTaggedPointerObfuscator(void)
{
if (!DisableTaggedPointerObfuscation && dyld_program_sdk_at_least(dyld_fall_2018_os_versions)) {
删除 && dyld_program_sdk_at_least(dyld_fall_2018_os_versions
注释
//#include <Cambria/Traps.h>
//#include <Cambria/Cambria.h>
//#include <os/linker_set.h>
// LINKER_SET_FOREACH(_dupi, const objc_duplicate_class **, “__objc_dupclass”) {
// const objc_duplicate_class *dupi = *_dupi;
//
// if (strcmp(dupi->name, name) == 0) {
// return;
// }
// }

//#include <os/feature_private.h>
//#include <os/reason_private.h>
//#include <os/variant_private.h>

// if (DebugPoolAllocation || sdkIsAtLeast(10_12, 10_0, 10_0, 3_0, 2_0)) {
// // OBJC_DEBUG_POOL_ALLOCATION or new SDK. Bad pop is fatal.
// _objc_fatal
// (“Invalid or prematurely-freed autorelease pool %p.”, token);
// }
接着出现
can’t open order file: Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/AppleInternal/OrderFiles/libobjc.order

解决
在这里插入图片描述
修改工程配置,将Build Settings->Linking->Order File改为工程根目录下的libobjc.order,即:$(SRCROOT)/libobjc.order。

接着又出现 library not found for -lCrashReporterClient
去Build Settings 搜索lCrashReporterClient 删除掉
debug 和release都删除
接着是这里修改把macosx.internal 改为 macosx
在这里插入图片描述
oh my god 编译成功了
真是不容易

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值