使用clang命令,將.m文件轉(zhuǎn)換成.cpp文件(cd到main.m的文件路徑下:)
clang -rewrite-objc main.m
若有異常:
如:
異常一:fatal error: ****'UIKit/UIKit.h'filenotfound#import <UIKit/UIKit.h> ^**1error generated.
則:
- 進(jìn)入終端,鍵入命令vim ~/.bash_profile
- 在vim界面輸入i進(jìn)入編輯編輯狀態(tài)并且鍵入:
alias rewriteoc='clang -x objective-c -rewrite-objc -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk'
- 鍵入完畢,點(diǎn)esc退出編輯狀態(tài),再鍵入:wq退出vim并保存,執(zhí)行source ~/.bash_profile<-這句一定要執(zhí)行,執(zhí)行才會(huì)生效。
異常二 :'UIWebView' is unavailable: not available on macOS
則:
- 指定真機(jī)
xcrun -sdk iphoneos clang -rewrite-objc main.m
- 指定模擬器
xcrun -sdk iphonesimulator clang -rewrite-objc main.m
- 指定SDK版本
xcrun -sdk iphonesimulator10.3 clang -rewrite-objc main.m
- ?語(yǔ)言轉(zhuǎn)C ++
clang -rewrite-objc main.c