1.编译objc4-838.1
1.1 编译环境
1.2 编译遇到的问题
1.2.1 unable to find sdk "macosx.internal"
解决办法如下:
将PROJECT
和TARGETS
里面Build Settings中的Base SDK改为macOS。
1.2.2 ’xxx.h‘ file not found
先来一个找不到文件的索引
找不到的文件 | 文件位置 |
---|---|
os/feature_private.h | xxxx.h |
sys/reason.h | bsd/sys/.h |
mach-o/dyld_priv.h | dyld/include/mach-o/dyld_priv.h |
os/lock_private.h | libplatform/private/include/os/lock_private.h |
os/base_private.h | xnu/libkern/os/base_private.h |
pthread/tsd_private.h | libpthread/private/pthread/tsd_private.h |
System/machine/cpu_capabilities.h | xnu/osfmk/machine/cpu_capabilities.h |
os/tsd.h | xnu/libsyscall/os/tsd.h |
pthread/spinlock_private.h | libpthread/private/spinlock_private.h |
System/pthread_machdep.h | libc/pthreads/pthread_machdep.h |
CrashReporterClient.h | libc/include/CrashReporterClient.h |
objc-shared-cache.h | dyld/include/objc-shared-cache.h |
Block_private.h | libclosure-79/Block_Private/Block_private.h |
os/reason_private.h | xnu/libkern/os/reason_private.h |
os/variant_private.h | libc/os/variant_private.h |
_simple.h | libplatform/private/_simple.h |
os/linker_set.h | xnu/bsd/sys/linker_set.h |
Cambria/Traps.h | xxxx.h |
kern/restartable.h | xnu/osfmk/kern/restartable.h |
注意上面图表中xxxx.h文件是苹果没有公布出来,不用费尽心思去找这些文件.
1.2.2.1 'os/feature_private.h' file not found
解决办法如下: 将引用feature_private.h的地方注释掉,即注释掉objc-runtime.mm中的36行与444~446行
// if (!os_feature_enabled_simple(objc4, preoptimizedCaches, true)) {
// DisablePreoptCaches = true;
// }
1.2.2.2 'sys/reason.h' file not found
该文件在xnu-8019.80.24文件的/bsd/sys/
目录下,下载xnu代码,在objc源码目录下建立一个include文件夹,再建立一个sys目录,将reason.h
文件放入,再前往objc的Build Settings设置Header Search Paths
如以下图示:
1.2.2.3 'mach-o/dyld_priv.h' file not found
1.该文件位于dyld/include/mach-o/
目录下面,下载dyld源码,在上面建立的include文件夹
中新建mach-o
文件夹,并且将dyld_priv.h
文件复制粘贴进去。
2.dyld_priv.h 报错语法错误 Expected ','
解决方案就是将报
Expected ','
错误的全部注释
1.2.2.4 'os/lock_private.h' file not found
该文件位于 libplatform/private/include/os/
目录下,同上下载libplatform源码.在include文件夹中建立os文件夹并且将lock_private.h文件复制粘贴进去。
1.2.2.5 'os/base_private.h' file not found
该文件同样位于 xnu/libkern/os/
目录下,同上将base_private.h文件复制粘贴进入os文件夹中即可。
1.2.2.6 'pthread/tsd_private.h' file not found
该文件位于libpthread/private/pthread
目录下,下载libpthread源码,在include文件夹中新建pthread文件夹并且将tsd_private.h文件复制粘贴进去.
1.2.2.7 'System/machine/cpu_capabilities.h' file not found
该文件位于 xnu/osfmk/machine/
目录下,在include文件夹中新建System文件夹,再System文件夹中新建machine文件夹,并且将tsd_private.h文件复制粘贴进machine文件夹去.
1.2.2.8 'os/tsd.h' file not found
该文件位于xnu/libsyscall/os/
目录中,同上复制粘贴文件到os文件夹
中。
1.2.2.9 'pthread/spinlock_private.h' file not found
该文件位于 libpthread/private/
目录中,同上复制粘贴文件到pthread文件夹
中。
1.2.2.10 'System/pthread_machdep.h' file not found
这个文件位于 libc/pthreads/
目录下,同上下载libc源码复制粘贴文件到System文件夹
中即可,如果最新的版本中没有,可以前往旧版本中寻找,Libc-583
版本中有该文件。
1.2.2.11 'CrashReporterClient.h' file not found
解决方案如下:
1.该文件位于 libc/include/
目录下,在Libc-Libc-1506.40.4
版本中没有CrashReportClient.h
文件。我找了一个Libc-997.90.3版本的,将CrashReporterClient.h复制粘贴到include文件中。
2.在target -> Build Setting -> Preprocessor Macros
中加入LIBC_NO_LIBCRASHREPORTERCLIENT
或者在CrashReporterClient.h
文件中更改了里面的宏信息 #define LIBC_NO_LIBCRASHREPORTERCLIENT
3.在Build Settings
-> Linking
-> Other Linker Flags
里删掉"-lCrashReporterClient"
,因为后面运行的时候会报错ld: library not found for -lCrashReporterClient
1.2.2.12 'objc-shared-cache.h' file not found
该文件位于dyld/include
目录下,将objc-shared-cache.h文件复制粘贴到include文件夹中。
1.2.2.13 'Block_private.h' file not found
该文件位于libclosure-79/Block_Private
中,下载libclosure-79源码,将Block_private.h文件拷贝到include文件夹中。
1.2.2.14 'os/reason_private.h' file not found
该文件位于xnu/libkern/os/
目录中,将reason_private.h文件复制粘贴到include/os文件夹中。
1.2.2.15 'os/variant_private.h' file not found
该文件位于libc/os/
目录中,将variant_private.h文件复制粘贴到include/os文件夹中。
1.2.2.16 '_simple.h' file not found
该文件位于libplatform/private/
目录中,将_simple.h文件复制粘贴到include文件夹中。
1.2.2.17 'os/linker_set.h' file not found
该文件位于xnu/bsd/sys
目录中,将linker_set.h文件复制粘贴到include/os文件夹中。
1.2.2.18 ‘Cambria/Traps.h’ file not found
注释掉下面的代码
1.2.2.19 'kern/restartable.h' file not found
该文件位于xnu/osfmk/kern
目录中,将restartable.h文件复制粘贴到include/kern文件夹中。
1.2.3 Use of undeclared identifier 'OS_UNFAIR_LOCK_ADAPTIVE_SPIN'
将上面代码改为
os_unfair_lock_lock(&mLock);
1.2.4 Use of undeclared identifier 'dyld_platform_version_macOS_10_13'
解决方案如下图:
1.2.5 Mismatch in debug-ness macros
注释报错地方的代码:
#error mismatch in debug-ness macros
1.2.6 Use of undeclared identifier 'dyld_fall_2020_os_versions'
注释掉下面代码
1.2.7 '_static_assert' declared as an array with a negative size
直接注释掉报错的地方
1.2.8 Use of undeclared identifier ‘dyld_fall_2018_os_versions’
删掉dyld_fall_2018_os_versions判断
1.2.9 ld: library not found for -loah
在Build Settings
-> Linking
-> Other Linker Flags
里删掉"-loah"
,
1.2.10 SDK "macosx.internal" cannot be located.
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
1.2.11 error: headers don't have symbol xxxxx
error: headers don't have symbol '_AltHandlerDebugLock'
error: headers don't have symbol '_AssociationsManagerLock'
error: headers don't have symbol '_CppObjectLocks'
error: headers don't have symbol '_DebugAltHandlers'
error: headers don't have symbol '_DebugDontCrash'
error: headers don't have symbol '_DebugDuplicateClasses'
error: headers don't have symbol '_DebugFragileSuperclasses'
error: headers don't have symbol '_DebugMissingPools'
error: headers don't have symbol '_DebugNilSync'
error: headers don't have symbol '_DebugNonFragileIvars'
error: headers don't have symbol '_DebugPoolAllocation'
error: headers don't have symbol '_DebugUnload'
error: headers don't have symbol '_DemangleCacheLock'
error: headers don't have symbol '_DisableInitializeForkSafety'
error: headers don't have symbol '_DisableNonpointerIsa'
error: headers don't have symbol '_DisablePreopt'
error: headers don't have symbol '_DisableTaggedPointerObfuscation'
error: headers don't have symbol '_DisableTaggedPointers'
error: headers don't have symbol '_DisableVtables'
error: headers don't have symbol '_FirstHeader'
error: headers don't have symbol '_LastHeader'
error: headers don't have symbol '_MultithreadedForkChild'
error: headers don't have symbol '_NXMapKeyCopyingInsert'
error: headers don't have symbol '_NXMapKeyFreeingRemove'
.....
解决方案:
-
选择
target
->objc
->Build Settings
-
Text-Based InstallAPI Verification Model
中添加搜索路径Errors Only
-
Other Text-Based InstallAPI Flags
清空所有内容
2.编译调试
1.新建一个macOS commandLine Target
,Objc4Test
:
2.绑定二进制依赖关系以及添加库
3.运行进行源码调试
这个时候断点能够进入,就大功告成。
总结:
如果自己的Target
编译调试遇见问题,尝试以下配置:
1: enable hardened runtime -> NO
2: 如果main
函数中断点断不住,尝试重新创建自己的Target
将main
放在Compile Sources
最前面。\