使用clang查看OC源码C++实现报错的处理

博客主要讲述了Clang错误产生的原因,即xcode10 ios12中stdlibc++头文件的包含路径未找到。给出了解决办法,如从xcode9中添加-lstdc++.6.0.9或网上找一个添加,还参考文章使用特定命令,虽有警告但可生成main.cpp进行分析,还提及查看xcode支持编译器sdk版本的命令。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

错误产生的原因:

include path for stdlibc++ headers not found; pass ‘-std=libc++’ on the command line to use
the libc++ standard library instead [-Wstdlibcxx-not-found]

xcode10 ios12已经彻底没有这个lib了

解决办法

直接去xcode9找到这-lstdc++.6.0.9 添加进去或者直接在网上找一个放进去,执行:

clang -x objective-c -rewrite-objc -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk main.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.
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]

经过一番查找,参考 https://cotin.tech/iOS/clang-rewrite-objc/
这篇文章,使用如下命令:

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

虽然还是有一些警告,但是实际上,对应的 main.cpp已经生产,可以进行分析了。

如果想知道当前的xcode支持哪些编译器sdk版本,可以使用以下命令:

xcodebuild -showsdks
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值