Xcode10適配libstdc++.6.0.9.tdb

一:引言

libstdc++ 自從 Xcode 8 宣布不建議使用后,終于在 Xcode 10 中被直接刪掉。其中包括 stdc++, stdc++.6.0.9, libstdc++.6.0.9.tbd(新的動(dòng)態(tài)庫), libstdc++.6.0.9.dylib(舊的動(dòng)態(tài)庫)。

二:適配過程

升級Xcode10之后的確如此,報(bào)錯(cuò):library not found for -lstdc++.6.0.9

錯(cuò)誤描述

看到有帖子說如果是第三方報(bào)這個(gè)錯(cuò),聯(lián)系第三方適配Xcode10。于是。。就有開發(fā)聯(lián)系了我,問我啥時(shí)候適配呢?好吧,我是做SDK的,那就趕緊適配吧。

方案一:Xcode 9 中 關(guān)于 libstdc++ 的文件復(fù)制一份到 Xcode 10 中

說實(shí)話,這個(gè)方案并不適合我,因?yàn)槲易龅牟皇琼?xiàng)目,而是SDK,我不能強(qiáng)制開發(fā)者這么做,這個(gè)是等待第三方適配的臨時(shí)方案吧。再一個(gè)我也試了試,真機(jī)沒有問題,但是模擬器在iOS12時(shí)會(huì)出現(xiàn)閃退。

方案二:重新編譯,使用到 libstdc++ 的 API 的庫重新修改代碼,鏈接到 libc++

SDK在Xcode10中真機(jī)正常運(yùn)行,但是模擬器下報(bào)錯(cuò)信息如下:

Undefined symbols for architecture x86_64:
  "std::_List_node_base::hook(std::_List_node_base*)", referenced from:
      std::list<AudioDataStruct*, std::allocator<AudioDataStruct*> >::_M_insert(std::_List_iterator<AudioDataStruct*>, AudioDataStruct* const&) in libLECPlayerFoundation.a(ios_audio_out.o)
      std::list<lec_pic_t*, std::allocator<lec_pic_t*> >::insert(std::_List_iterator<lec_pic_t*>, lec_pic_t* const&) in libLECPlayerFoundation.a(ios_video_dec.o)
      std::list<lec_pic_t*, std::allocator<lec_pic_t*> >::_M_insert(std::_List_iterator<lec_pic_t*>, lec_pic_t* const&) in libLECPlayerFoundation.a(ios_video_dec.o)
  "std::_List_node_base::unhook()", referenced from:
      std::list<AudioDataStruct*, std::allocator<AudioDataStruct*> >::_M_erase(std::_List_iterator<AudioDataStruct*>) in libLECPlayerFoundation.a(ios_audio_out.o)
      std::list<lec_pic_t*, std::allocator<lec_pic_t*> >::_M_erase(std::_List_iterator<lec_pic_t*>) in libLECPlayerFoundation.a(ios_video_dec.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

很明顯是在報(bào)的錯(cuò)是C++的API沒有找到支持庫。于是打開SDK源碼,我是用腳本來編譯出來的.a文件??刺O果官方的介紹可以得知,C++需要重新編譯鏈接到libc++庫,我的操作是在clang語句中加入-stdlib=libc++。

編譯出.a文件,重新替換工程中的舊.a文件,在Xcode10下真機(jī)和模擬器都可以正常運(yùn)行。適配成功。

想知道Xcode10有哪些新特性,看這里What's new in Xcode 10

本文章在2018年9月首發(fā)在CSDN

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容