objc源码编译
一、环境配置
- macOS:10.15.7
- Xcode:12.4
- objc4-818.2
依赖项目
所有的源码都可以在opensource中找到。
二、配置
首先选中objc target
进行编译。
-
unable to find sdk 'macosx.internal'
image.png
修改脚本macosx.internal
为macosx
:
image.png
并且修改basesdk
为macOS
:
2.'sys/reason.h' file not found
在项目根目录创建自己的文件夹,我这来是HPCommon
,将xnu
中的bsd/sys
目录中的sys/reason.h
文件拷贝到这个目录中:
配置
Search Header
:image.png
同理:
错误 | 库 | 目录 |
---|---|---|
'mach-o/dyld_priv.h' file not found |
dyld |
include/mach-o |
'os/lock_private.h' file not found |
libplatform |
os/lock_private.h |
'os/base_private.h' file not found |
xnu |
os/base_private.h |
'pthread/tsd_private.h' file not found |
libpthread |
pthread/tsd_private.h |
'System/machine/cpu_capabilities.h' file not found |
xnu |
System/machine/cpu_capabilities.h (osfmk/machine/ 目录下的) |
'os/tsd.h' file not found |
xnu |
os/tsd.h |
'pthread/spinlock_private.h' file not found |
libpthread |
pthread/spinlock_private.h |
'System/pthread_machdep.h' file not found |
libc |
System/pthread_machdep.h libc新版本中没有找打,老版本有
|
'CrashReporterClient.h' file not found |
libc |
CrashReporterClient.h' libc新版本中没有找打,老版本有
|
'os/linker_set.h' file not found |
Libc |
os/linker_set.h |
'Cambria/Traps.h' file not found |
xnu |
Cambria/Traps.h |
'_simple.h' file not found |
libplatform |
_simple.h |
'Cambria/Cambria.h' file not found |
注释掉 | |
'kern/restartable.h' file not found |
xnu |
kern/restartable.h |
'os/feature_private.h' file not found |
注释 | |
objc-bp-assist.h' file not found |
注释 | |
'objc-shared-cache.h' file not found |
dyld |
objc-shared-cache.h |
'os/feature_private.h' file not found |
注释 | |
'os/reason_private.h' file not found |
注释 | |
'os/variant_private.h' file not found |
注释 | |
'Block_private.h' file not found |
libclourse |
Block_private.h |
还需要增加LIBC_NO_LIBCRASHREPORTERCLIENT
宏定义:
3.Expected ','
注释掉
bridgeos
相关内容:image.png
4.Use of undeclared identifier 'dyld_platform_version_macOS_10_11'
直接注释掉。
5.Use of undeclared identifier 'oah_is_current_process_translated'
直接注释
-
Use of undeclared identifier 'dyld_fall_2020_os_versions'
image.png
注释
7.Use of undeclared identifier 'objc4'
注释
8.'_static_assert' declared as an array with a negative size
注释
9.Use of undeclared identifier 'dyld_platform_version_macOS_10_13'
注释
10.Use of undeclared identifier 'dyld_fall_2018_os_versions'
修改
11.Use of undeclared identifier 'dyld_platform_version_bridgeOS_2_0'
注释
-
libobjc.order 路径问题
image.png
can't open order file: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/AppleInternal/OrderFiles/libobjc.order
-
image.pnglibrary not found for -lCrashReporterClient
release
和debug
都删除。
14.library not found for -loah
删除
-loah
。
这个时候一般能正常编译通过了。
三、编译调试
-
新建一个
image.pngmacOS commandLine Target
,HPObjcTest
:
-
绑定二进制依赖关系
image.png -
运行进行源码调试
image.png
image.png
这个时候断点能够进入,就大功告成。
总结:
如果自己的Target
编译调试遇见问题,尝试以下配置:
1: enable hardened runtime -> NO
2: build phase -> denpendenice -> objc
3: 如果main
函数中断点断不住,尝试重新创建自己的Target
将main
放在Compile Sources
最前面。
可以直接下载我编译好的进行调试objc4-818.2编译好的源码
参考:
https://juejin.cn/post/6844903959161733133