clang编译错误: fatal error: 'UIKit/UIKit.h' file not found

错误

这是一个使用clang编译器Objective-C代码编译成C语言代码, 并生成在一个.cpp的 C++文件中。具体的命令行是:

$ cd 当前文件夹
$ clang -rewrite-objc SomeFile.m

这是, 可能会遇到一个错误就是如下:
这里写图片描述

fatal error: 'UIKit/UIKit.h' file not found
#import <UIKit/UIKit.h>
        ^~~~~~~~~~~~~~~
1 error generated.

解决

将之前执行的命令替换成为:

$ clang -x objective-c -rewrite-objc -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk SomeFile.m

然后, 你会发现, 你的文件夹中多了一个.cpp的文件, 证明解决了这个问题。

拓展

如果你觉得这个命令很繁琐不易记, 你可以采用 alias来起一个别名来代替这个命令。
1.打开终端, 键入命令 vim ~/.bash_profile
2.在vim界面输入i进入编辑编辑状态并且键入:

alias rewriteoc=’clang -x objective-c -rewrite-objc -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk’

3.键入完毕后, esc退出编辑状态, 再键入:wq退出vim并保存
4.键入命令source ~/.bash_profile

参考资料:
iOS: XCode 4.5: xcodebuild error - fatal error: ‘UIKit/UIKit.h’ file not found

猜你喜欢

转载自blog.csdn.net/wangyanchang21/article/details/79608668
今日推荐