XCode: duplicate symbol
http://hmifly.blog.163.com/blog/static/128583507201342752241781/
遇到引用庫重複定義的問題,需要解決。
duplicate symbol _base64_encode in:
...\libzbar.a(symbol.o)
...\TencentOpenAPI(base64.o)
意思就是在這兩個庫中都定義了_base64_encode,編譯器認爲你重複定義了。至於爲什麼編譯器認爲重複定義,個人認爲編譯器編譯全局變量時會根據名字進行編譯,會把相同名稱的全局變量編譯爲相同變量,也就是多個編譯成一個,而編譯器認爲這樣可能會引起錯誤,就提醒用戶這裏有錯。
解決方案:
參考了:http://blog.sina.com.cn/s/blog_4beb28f301012bl6.html
刪掉了 set building->other linker flag-> -all_load
在Build Settings->Other link flags中刪除所有的-all_load與-force_load, XCode會很smart的去掉"Duplicate Symbol"。
假設有兩個三方類庫僅提供給你了.a文件,沒有源碼,你可以通過libtool, lipo和ar在terminal中解壓合併他們。
To see what architectures are in the file:
查看文件都支持了什麼架構
$ 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:
你可以從另一個類庫中解壓同樣架構的部分,然後將兩者合併在一起
$ 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:
如上所示,你可以將所有架構都按照這個流程走一遍,然後合併
$ 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.