从https://opensource.apple.com/releases/中下载objc4最新版源码,解压编译
错误1:unable to find sdk 'macosx.internal'
- 解决方案:将
TARGETS
中objc
、objc-simulator
、objc-trampolines
的Build Settings-->Base SDK
改为macOS
错误2:'sys/reason.h' file not found
-
解决方案:
第一步:下载reason.h文件1. 通过[Apple source](https://opensource.apple.com/releases/)在最新版xnu-8792.41.9/bsd/sys/reason.h路径下载 2. 通过谷歌输入`reason.h site:opensource.apple.com` 定向检索
第二步:把文件放入到工程中:在objc4工程根目录创建新文件夹Common/sys,将reason.h文件放入文件夹中
第三步: 在工程设置文件的检索路径
- 选择target->objc->Build Settings
- Header Search Paths-->$(SRCROOT)/Common
其他file not found错误解决方案同上
- mach-o/dyld_priv.h:在objc4工程根目录创建新文件夹
Common/mach-o
,将dyld_priv.h文件放入文件夹中
dyld_priv.h中报错Expected ',':删掉文件中的所有, bridgeos(~.0)
- os/lock_private.h :将lock_private.h文件放入Common/os文件夹中
Expected ','
:删掉, bridgeos(4.0)
-
os/base_private.h:将base_private.h文件放入Common/os文件夹中
- pthread/tsd_private.h:在objc4工程根目录创建新文件夹
Common/pthread
,将tsd_private.h文件放入文件夹中
- machine/cpu_capabilities.h:把错误处改成
#include <System/machine/cpu_capabilities.h>
,在objc4工程根目录创建新文件夹Common/System/machine
,将cpu_capabilities.h文件放入文件夹中
-
os/feature_private.h:直接注释
-
os/tsd.h:将tsd.h文件放入Common/os文件夹中
-
os/variant_private.h
- System/pthread_machdep.h
在https://opensource.apple.com/source/Libc/Libc-583/pthreads/下载pthread_machdep.h文件,在objc4工程根目录创建新文件夹Common/System
,将pthread_machdep.h文件放入文件夹中
文件报错:Static declaration of 'pthread_has_direct_tsd’ follows non-static declaration、
_Static declaration of ‘_pthread_getspecific_direct’ follows non-static declaration、
Static declaration of ‘_pthread_setspecific_direct’ follows non-static declaration-
解决方案:注释掉报错的方法
- variant_private.h文件报错:删掉
, bridgeos(4.0)
- variant_private.h文件报错:删掉
-
System/machine/cpu_capabilities.h
- CrashReporterClient.h
在https://opensource.apple.com/source/Libc/Libc-997.90.3/include/CrashReporterClient.h.auto.html处下载,放在/Common文件夹下
依然报错:在 Build Settings -> Preprocessor Macros 中加入: LIBC_NO_LIBCRASHREPORTERCLIENT
#include_next<CrashReporterClient.h>改为
#include <CrashReporterClient.h>
-
Block_private.h
-
objc-shared-cache.h
-
os/linker_set.h
Use of undeclared identifier 'dyld_platform_version_macOS_10_13':直接注释报错代码
-
_simple.h
-
sandbox/private.h
注释掉,编译后出错,出错的代码也注释掉,再添加一行_simple_asl_log(ASL_LEVEL_ERR, nil, message);
- os/bsd.h和Cambria/Traps.h和Cambria/Cambria.h:注释
-
kern/restartable.h
-
os/reason_private.h
-
Use of undeclared identifier 'dyld_platform_version_macOS_10_12'直接注释
-
"macosx.internal" cannot be located.
其他file not found错误 和 Use of undeclared identifier错误 都注释掉代码即可
- library not found for -loah:在objc->Build Settings->Other Linker Flags中删除-loah
编译成功!
调试objc源码
- 新建target:macOS --> Command Line Tool --> objcBuildDemo
- 选择 target -> objcBuildDemo -> General -> Frameworks and Libraries ,点击"+"添加 libobjc.A.dylib
- 检查target -> objcBuildDemo -> Build Phases,看一下Target Dependencies中是否有objc,Link Binary With Libraries中是否有 libobjc.A.dylib,没有则添加
- 将Build Settings中将Enable Hardened Runtime设置为NO,否则在objc源码下的断点没法断住,这个是Xcode 11的新特性
-
如果断点断不住,需要将target -> objcBuildDemo -> Build Phases->Compile Sources里面的main.m放在最前面
TODO
调试时报错:This version of LLDB has no plugin for the language "assembler". Inspection