当前位置: 首页>编程语言>正文

通过clang看OC底层C++文件

想了解oc底层的c++文件是怎样的,然后执行clang -rewrite-objc ViewController.m时报错

In file included from ViewController.m:9:
./ViewController.h:9:9: 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 xxxxx.m

可通过alias简化如下:

1、进入终端输入
vim ~/.bash_profile

2、在vim界面输入i进入编辑状态然后输入:
alias writeoctoc='clang -x objective-c -rewrite-objc -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk'

3、点esc退出编辑状态,再键入:wq(退出vim并保存),执行source ~/.bash_profile
4、进入你想要编译的文件目录
通过clang看OC底层C++文件,第1张
8447B1D5-7FB4-451A-8FF4-A271A3704CA4.png
5、执行writeoctoc xxx.m即可成功
通过clang看OC底层C++文件,第2张
9B49252D-75DA-4F0C-8C6C-E9ED56A05572.png
通过clang看OC底层C++文件,第3张
94221A85-F0F0-4B03-8516-24DD4A5823A8.png

https://www.xamrdz.com/lan/5tw2016179.html

相关文章: