通过runtime转换OC为c++,在终端执行
$ clang -rewrite-objc /Users/sanyolewis/Desktop/ffsdf/ffsdf/AppDelegate.m
但是会报错,
$ clang -rewrite-objc /Users/sanyolewis/Desktop/ffsdf/ffsdf/AppDelegate.m
In file included from /Users/sanyolewis/Desktop/ffsdf/ffsdf/AppDelegate.m:9:
/Users/sanyolewis/Desktop/ffsdf/ffsdf/AppDelegate.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 hahahah.m
但是每次这么输入太繁琐,因此可以通过alias进行简化处理
$ vim ~/.bash_profile
source ~/.profile
alias rewriteoc='clang -x objective-c -rewrite-objc -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk'
[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"~/.bash_profile" 5L, 393C
然后保存退出,ESC + :wq
$ source ~/.bash_profile
$ rewriteoc /Users/sanyolewis/Desktop/LearnOpenGLES-master/LearnOpenGLES/LearnOpenGLES/AppDelegate.m
clang: warning: using sysroot for 'iPhoneSimulator' but targeting 'MacOSX' [-Wincompatible-sysroot]
/var/folders/7f/z7cl7cqs1svctn_dcq8kccjw0000gn/T/AppDelegate-b92d03.mi:12793:188: warning:
'kCFCalendarUnitWeek' is deprecated: first deprecated in macOS 10.10 - Use
kCFCalendarUnitWeekOfYear or kCFCalendarUnitWeekOfMonth instead
[-Wdeprecated-declarations]
...or NSCalendarUnitWeekOfYear, depending on which you mean"))) = kCFCalend...
^
/var/folders/7f/z7cl7cqs1svctn_dcq8kccjw0000gn/T/AppDelegate-b92d03.mi:5142:2: note:
'kCFCalendarUnitWeek' has been explicitly marked deprecated here
kCFCalendarUnitWeek __attribute__((availability(macos,introduced=10.4,d...
^
1 warning generated.
这时已经有一个后缀为.cpp的C++文件了。