环境
- Xcode12.3 iPhoneOS14.3.sdk
- 光 2020.05.04Signed
- theos (https://github.com/theos/theos)
使用theos新建默认tweak工程,在Tweak.x里引入 #import <Foundation/Foundation.h>,同时,修改Makefile,在里面指定使用光:
_THEOS_TARGET_CC := /Library/Developer/Toolchains/光.xctoolchain/usr/bin/clang
_THEOS_TARGET_CXX := /Library/Developer/Toolchains/光.xctoolchain/usr/bin/clang++
使用的测试工程如下:
testtweak.zip (1.8 KB)
报错信息
==> Compiling Tweak.x (arm64)…
While building module 'Foundation' imported from Tweak.x:2:
In file included from <module-includes>:1:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:39:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSFileManager.h:11:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSURL.h:10:9: fatal error: 'Foundation/NSURLHandle.h' file not found
#import <Foundation/NSURLHandle.h>
^~~~~~~~~~~~~~~~~~~~~~~~~~
Tweak.x:2:9: fatal error: could not build module 'Foundation'
#import <Foundation/Foundation.h>
~~~~~~~^
2 errors generated.
尝试解决
1. 在makefile里增加编译参数消宏定义
报错出现在文件NSURL.h里:
#if TARGET_OS_OSX || TARGET_OS_MACCATALYST
#import <Foundation/NSURLHandle.h>
#endif
在Makefile里增加参数:
testtweak_CFLAGS := -DTARGET_OS_OSX\=0 -DTARGET_OS_MACCATALYST\=0 -DTARGET_OS_IPHONE -DTARGET_OS_IOS
结果:仍然报错
2. 使用Xcode11.7
结果:编译成功,不再报错
看了下Xcode 11.7 里 也保留有 #if TARGET_OS_OSX || TARGET_OS_MACCATALYST 定义,
该版本可以编译过,不知道哪里环境配置有问题,看看有没有大佬遇到这个问题呢?