android代码转oc代码,使用clang将OC代码转为C++(亲测有效)

最近在研究RunLoop运行机制,想看看他的底层代码是什么样子的,于是百度看看大家如何操作的。最终绝望的发现基本的操作都一样,然并卵。

zhangquaniMac:3456 zq$ cd /Users/zq/Desktop/3456/3456

zhangquaniMac:3456 zq$ clang -x objective-c -rewrite-objc -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk ViewController.m

显示异常如下:

clang: warning: using sysroot for 'iPhoneSimulator' but targeting 'MacOSX' [-Wincompatible-sysroot]

warning: include path for stdlibc++ headers not found; pass '-std=libc++' on the

command line to use the libc++ standard library instead

[-Wstdlibcxx-not-found]

1 warning generated.

/var/folders/qc/wbfmgr1x6f9246c0jt6yqt100000gn/T/ViewController-4ce726.mi:12856: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/qc/wbfmgr1x6f9246c0jt6yqt100000gn/T/ViewController-4ce726.mi:5156:2: note:

'kCFCalendarUnitWeek' has been explicitly marked deprecated here

kCFCalendarUnitWeek __attribute__((availability(macos,introduced=10.4,d...

^

/var/folders/qc/wbfmgr1x6f9246c0jt6yqt100000gn/T/ViewController-4ce726.mi:22487:16: warning:

'ns_returns_retained' attribute only applies to functions that return an

Objective-C object [-Wignored-attributes]

__attribute__((__ns_returns_retained__)) _Nullable sec_trust_t

^

/var/folders/qc/wbfmgr1x6f9246c0jt6yqt100000gn/T/ViewController-4ce726.mi:22493:16: warning:

'ns_returns_retained' attribute only applies to functions that return an

Objective-C object [-Wignored-attributes]

__attribute__((__ns_returns_retained__)) _Nullable sec_identity_t

^

/var/folders/qc/wbfmgr1x6f9246c0jt6yqt100000gn/T/ViewController-4ce726.mi:22496:16: warning:

'ns_returns_retained' attribute only applies to functions that return an

Objective-C object [-Wignored-attributes]

__attribute__((__ns_returns_retained__)) _Nullable sec_identity_t

^

/var/folders/qc/wbfmgr1x6f9246c0jt6yqt100000gn/T/ViewController-4ce726.mi:22505:16: warning:

'ns_returns_retained' attribute only applies to functions that return an

Objective-C object [-Wignored-attributes]

__attribute__((__ns_returns_retained__)) _Nullable sec_certificate_t

^

/var/folders/qc/wbfmgr1x6f9246c0jt6yqt100000gn/T/ViewController-4ce726.mi:22521:16: warning:

'ns_returns_retained' attribute only applies to functions that return an

Objective-C object [-Wignored-attributes]

__attribute__((__ns_returns_retained__)) _Nullable dispatch_data_t

^

/var/folders/qc/wbfmgr1x6f9246c0jt6yqt100000gn/T/ViewController-4ce726.mi:22555:16: warning:

'ns_returns_retained' attribute only applies to functions that return an

Objective-C object [-Wignored-attributes]

__attribute__((__ns_returns_retained__)) _Nullable dispatch_data_t

^

/var/folders/qc/wbfmgr1x6f9246c0jt6yqt100000gn/T/ViewController-4ce726.mi:22559:16: warning:

'ns_returns_retained' attribute only applies to functions that return an

Objective-C object [-Wignored-attributes]

__attribute__((__ns_returns_retained__)) _Nullable dispatch_data_t

^

/var/folders/qc/wbfmgr1x6f9246c0jt6yqt100000gn/T/ViewController-4ce726.mi:50310:13: warning:

'CADisplayLink' is only available on macOS 10.14 or newer

[-Wunguarded-availability-new]

- (nullable CADisplayLink *)displayLinkWithTarget:(id)target selector:(S...

^

/var/folders/qc/wbfmgr1x6f9246c0jt6yqt100000gn/T/ViewController-4ce726.mi:33690:12: note:

'CADisplayLink' has been explicitly marked partial here

@interface CADisplayLink : NSObject

^

/var/folders/qc/wbfmgr1x6f9246c0jt6yqt100000gn/T/ViewController-4ce726.mi:50310:1: note:

annotate 'displayLinkWithTarget:selector:' with an availability attribute

to silence this warning

- (nullable CADisplayLink *)displayLinkWithTarget:(id)target selector:(S...

^

/var/folders/qc/wbfmgr1x6f9246c0jt6yqt100000gn/T/ViewController-4ce726.mi:52754:18: error:

'UIWebView' is unavailable: not available on macOS

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRe...

^

/var/folders/qc/wbfmgr1x6f9246c0jt6yqt100000gn/T/ViewController-4ce726.mi:52702:281: note:

'UIWebView' has been explicitly marked unavailable here

...__attribute__((availability(macos,unavailable))) @interface UIWebView : ...

^

/var/folders/qc/wbfmgr1x6f9246c0jt6yqt100000gn/T/ViewController-4ce726.mi:52755:30: error:

'UIWebView' is unavailable: not available on macOS

- (void)webViewDidStartLoad:(UIWebView *)webView __attribute__((availabi...

^

/var/folders/qc/wbfmgr1x6f9246c0jt6yqt100000gn/T/ViewController-4ce726.mi:52702:281: note:

'UIWebView' has been explicitly marked unavailable here

...__attribute__((availability(macos,unavailable))) @interface UIWebView : ...

^

/var/folders/qc/wbfmgr1x6f9246c0jt6yqt100000gn/T/ViewController-4ce726.mi:52756:31: error:

'UIWebView' is unavailable: not available on macOS

- (void)webViewDidFinishLoad:(UIWebView *)webView __attribute__((availab...

^

/var/folders/qc/wbfmgr1x6f9246c0jt6yqt100000gn/T/ViewController-4ce726.mi:52702:281: note:

'UIWebView' has been explicitly marked unavailable here

...__attribute__((availability(macos,unavailable))) @interface UIWebView : ...

^

/var/folders/qc/wbfmgr1x6f9246c0jt6yqt100000gn/T/ViewController-4ce726.mi:52757:18: error:

'UIWebView' is unavailable: not available on macOS

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)err...

^

/var/folders/qc/wbfmgr1x6f9246c0jt6yqt100000gn/T/ViewController-4ce726.mi:52702:281: note:

'UIWebView' has been explicitly marked unavailable here

...__attribute__((availability(macos,unavailable))) @interface UIWebView : ...

^

9 warnings and 4 errors generated.

试了多次,发现还是报同样的错误,于是只能继续耐心的看看还有没有不同的操作,最终得到了一个完美的操作:

zhangquaniMac:~ zq$ cd /Users/zq/Desktop/3456/3456

zhangquaniMac:3456 zq$ xcrun -sdk iphonesimulator clang -rewrite-objc ViewController.m

转换成功

format,png

补充一下

指定真机

xcrun -sdk iphoneos clang -rewrite-objc ViewController.m

指定模拟器

xcrun -sdk iphonesimulator clang -rewrite-objc ViewController.m

指定SDK版本

xcrun -sdk iphonesimulator10.3 clang -rewrite-objc ViewController.m

C语言转C ++

zhangquaniMac:~ zq$ cd /Users/zq/Desktop/Test/Test

zhangquaniMac:Test zq$ clang -rewrite-objc main.c

作者:蜗牛非牛

链接:https://www.jianshu.com/p/bd6a94d8e49b

来源:简书

简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值