Xcode 10 library not found for -lstdc++.6

最近升级了Xcode 10,发现编译的时候报如下错误,在Xcode 9上正常:

library not found for -lstdc++.6

这个是因为iOS 12废弃了libstdc++,也删除了相关的库,改为使用libc++替代

解决方案

将缺失的库拷贝到原来对应的目录下,使Xcode能够引用

将相应的库拷贝到如下四个目录当中,才能保证模拟器和真机都能用,缺少哪个库拷贝哪个就行,不用全部拷贝

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/

文件下载:libstdc++

其他

如果拷贝进去之后重启Xcode编译还是报这个错误,建议在TARGETS->Build Phases->Link Binary With Libraries当中把当前依赖添加进去

多说两句

这种方法虽然可以暂时解决问题,但最好还是升级下相关库,使用新的库和API。