導(dǎo)入框架時(shí)遇到這個(gè)問(wèn)題,開(kāi)始一直以為是路徑之類的問(wèn)題,一直沒(méi)有得到解決后來(lái)網(wǎng)上查詢資料,得到是因?yàn)橐脦?kù)重復(fù)定義的原因
網(wǎng)上查詢資料參考
http://hmifly.blog.163.com/blog/static/128583507201342752241781/
PS:以下是直接的原文,留著自己看了!
項(xiàng)目需要,同時(shí)引用ZBar和
QQ授權(quán)登錄SDK,由于二者均使用了Base64處理數(shù)據(jù),XCode編譯時(shí)報(bào)錯(cuò):
duplicate symbol _base64_encode in:
.../libzbar.a(symbol.o)
.../TencentOpenAPI(base64.o)
意思就是在這兩個(gè)庫(kù)中都定義了_base64_encode,編譯器認(rèn)為你重復(fù)定義了。至于為什么編譯器認(rèn)為重復(fù)定義,個(gè)人認(rèn)為編譯器編譯全局變量時(shí)會(huì)根據(jù)名字進(jìn)行編譯,會(huì)把相同名稱的全局變量編譯為相同變量,也就是多個(gè)編譯成一個(gè),而編譯器認(rèn)為這樣可能會(huì)引起錯(cuò)誤,就提醒用戶這里有錯(cuò)。
解決方案:
參考了:http://blog.sina.com.cn/s/blog_4beb28f301012bl6.html
刪掉了 set building->other linker flag-> -all_load
ios的Framework是共享動(dòng)態(tài)庫(kù),不會(huì)被打包到app中,非系統(tǒng)Framework靜態(tài)庫(kù)都會(huì)被打包到app中,所以會(huì)產(chǎn)生"Duplicate Symbol"的錯(cuò)誤。
在Build Settings->Other link flags中刪除所有的-all_load與-force_load, XCode會(huì)很smart的去掉"Duplicate Symbol"。
以下是從外國(guó)友人那獲取的終極解決策略,方案是修改類庫(kù):
I'm going to assume that these are two third party libraries that have only PRovided you with the .a files and not the source code. You can use libtool, lipo and ar on the terminal to extract and recombine the files.
假設(shè)有兩個(gè)三方類庫(kù)僅提供給你了.a文件,沒(méi)有源碼,你可以通過(guò)libtool, lipo和ar在terminal中解壓合并他們。
To see what architectures are in the file:
查看文件都支持了什么架構(gòu)
$ lipo -info libTapjoy.a
Architectures in the fat file: libTapjoy.a are: armv6 i386
Then to extract just armv6, for example:
然后只解壓armv6,例如
$ lipo -extract_family armv6 -output libTapjoy-armv6.a libTapjoy.a
$ mkdir armv6
$ cd armv6
$ ar -x ../libTapjoy-armv6.a
You can then extract the same architecture from the other library into the same directory and then recombine them like so:
你可以從另一個(gè)類庫(kù)中解壓同樣架構(gòu)的部分,然后將兩者合并在一起
$ libtool -static -o ../lib-armv6.a *.o
And then finally, after you've done this with each architecture, you can combine them again with lipo:
如上所示,你可以將所有架構(gòu)都按照這個(gè)流程走一遍,然后合并
$ cd ..
$ lipo -create -output lib.a lib-armv6.a lib-i386.a
This should get rid of any duplicate symbols, but will also combine the two libraries into one. If you want to keep them separate, or just delete the duplicate from one library, you can modify the process accordingly. 這個(gè)過(guò)程不僅解決掉了duplicate symbols的問(wèn)題,也將兩個(gè)類庫(kù)合并為一個(gè)。如果你想分別保存兩個(gè)類庫(kù),你可以將duplicate的部分從任意一個(gè)類庫(kù)中刪除,你可以相應(yīng)的修改這個(gè)過(guò)程。
總結(jié):按照上述刪掉-all_load后問(wèn)題得到解決!