項目中用到Three20框架,同時也使用了訊飛語音的framework,編譯時出現類似如下衝突提示信息:
ld: duplicate symbol _OBJC_CLASS_$_AdLinks in /Users/w/Documents/project 2/dianxing_v2.00_code_reconfiguration/iFlyLib/iFlyTTS.framework/iFlyTTS(AdvertiseDataDefine.o) and /Users/w/Documents/project 2/dianxing_v2.00_code_reconfiguration/iFlyLib/iFlyISR.framework/iFlyISR(AdvertiseDataDefine.o)
for architecture i386
Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/clang failed with exit code 1
網上收集了一下對於該問題的解答,感覺還比較靠譜,粘貼如下:
個人猜想,大概是在iFlyTTS和iFlyISR在編譯的時候,都加入了AdvertiseDataDefine.m(AdvertiseDataDefine.o)這個文件,而裏面包含了AdLinks這個類的category。在一般的鏈接參數下倒是沒有問題(因爲category的鏈接被忽略了),但是如果引入了Three20,於是就加入了-ObjC - all_load這個參數(沒辦法,這個參數對於Three20的運行時必須的),於是這個鏈接錯誤就表現出來了(於是鏈接時就出現了duplicate symbol
_OBJC_CLASS_$_AdLinks in iFlyTTS(AdvertiseDataDefine.o) and iFlyISR(AdvertiseDataDefine.o) for architecture XXXX)。
解決方案:修改鏈接參數(Other Linker Flag)
1.去掉-ObjC -all_load參數(這個參數會強制所有的靜態鏈接庫都加載其中的category);
2.改爲逐一加載Three20的各個靜態庫,即修改鏈接參數(Other Linker Flag)爲如下形式:
-force_load $(BUILT_PRODUCTS_DIR)/libThree20.a
-force_load $(BUILT_PRODUCTS_DIR)/libThree20UINavigator.a
-force_load $(BUILT_PRODUCTS_DIR)/libThree20UICommon.a
-force_load $(BUILT_PRODUCTS_DIR)/libThree20UI.a
-force_load $(BUILT_PRODUCTS_DIR)/libThree20Style.a
-force_load $(BUILT_PRODUCTS_DIR)/libThree20Network.a
-force_load $(BUILT_PRODUCTS_DIR)/libThree20Core.a
ps:寫這篇文章主要目的是爲了說明,在碰到Three20和其他framework衝突的時候,可以考慮一下逐個加載Three20的lib,而不是使用-ObjC - all_load參數一次性強制加入。