Xcode10、Xcode 11 运行老程序报错dyld: Library not loaded: /usr/lib/libstdc++.6.dylib解决方案

控制台输出报错内容:

dyld: Library not loaded: /usr/lib/libstdc++.6.dylib
  Referenced from: /Users/yangming/Library/Developer/CoreSimulator/Devices/14C9AC08-7C07-4CED-A8EC-E93D0EA73953/data/Containers/Bundle/Application/73F84C0D-9D2D-474D-9947-F249B0CEEB15/CreatingCEP.app/CreatingCEP
  Reason: no suitable image found.  Did find:
    /usr/lib/libstdc++.6.dylib: mach-o, but not built for iOS simulator
(lldb) 

这个错误原因是因为iOS12.0之后去掉了lstdc++.6.0.9.tbd动态库,如下图搜索便知:


image.png

iOS12.0中全部采用libc++代替lstdc++的动态库(如下图)


image.png

解决方案

Xcode10下:

/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/

Xcode11下:
第一条iOS.simruntime的路径发生了变更,Xcode10中是../Developer/Library/..,而Xcode11中是.../Library/Developer/...

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/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/
为了方便大家,在此提供lstdc++动态库文件下载和DeviceSupport下载 链接:

libstdc

文章参考自:https://www.jianshu.com/p/3afd5e8cdbf8

推荐阅读更多精彩内容