編譯報錯
當(dāng)你開心得升級完新 macOS隔崎,以及新 XCode域蜗,準(zhǔn)備體驗了一把 Dark Mode 編程模式爷抓,開心的打開自己的老項目的時候,發(fā)現(xiàn)編譯不通過了╮(╯_╰)╭
如果你的工程中如果依賴?libstdc++盆赤,無論是你本身的功能用 C++ 跨平臺編寫,還是你引入了某個 SDK 其內(nèi)部依賴這個?libstdc++,都會導(dǎo)致整個工程編譯不通過歉眷,報出?Undefined symbols牺六,C++ 的 List 找不到了
原因是蘋果在 XCode10 和 iOS12 中移除了?libstdc++?這個庫,由?libc++?這個庫取而代之汗捡,蘋果的解釋是?libstdc++?已經(jīng)標(biāo)記為廢棄有5年了淑际,建議大家使用經(jīng)過了 llvm 優(yōu)化過并且全面支持C++11的?libc++?庫。
臨時解決辦法
拷貝缺失的libstdc++
在 XCode10 正式發(fā)布前凉唐,XCode10 目前是 Beta 版,和 XCode9 正式版可以共存
于是從 XCode9 的目錄里霍骄,把缺失的 .tbd 文件拷貝過來台囱,要記得拷貝2套,一套是模擬器的读整,一套是設(shè)備的簿训,可以簡單的用下面的命令
cp /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/libstdc++.* /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/
cp /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/libstdc++.* /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/
現(xiàn)在 XCode10 正式發(fā)布了,很多人已經(jīng)沒有 XCode9 來拷貝了米间,于是這里放出來文件提供下載
下載地址
?https://github.com/codesourse/libstdc-
iPhoneOS ?放到目錄
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/
拷貝libstdc++之后就可以編譯通過了强品,但 App 在模擬器里一運行就崩潰,就會報動態(tài)鏈接庫裝載出錯屈糊,看出錯提示說是 .dylib 與這個模擬器不符合的榛。這是 XCode10 自帶的 iOS12 模擬器的問題,在 XCode10 中安裝 iOS11 的模擬器運行環(huán)境逻锐,然后切換到 iOS11 模擬器運行夫晌,一切問題沒有。如果想在 XCode12 iOS12 模擬器中運行:
RuntimeRoot?放到目錄
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/
iPhoneSimulator?放到目錄
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/
補:運行模擬器還是會報錯
Reason: no suitable image found. Did find: /usr/lib/libstdc++.6.dylib: mach-o, butnotbuiltforiOS simulator
需要?RuntimeRoot 的?libstdc++.6.0.9.dylib 改?libstdc++.6.dylib 粘貼到?
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/