標籤:
在工程中匯入XMPP第三庫時,出現link錯誤,錯誤如下:
Undefined symbols for architecture i386:
"_iconv", referenced from:
_mem_cd_iconv in libidn.a(striconv.o)
_str_cd_iconv in libidn.a(striconv.o)
(maybe you meant: _str_iconv, _str_cd_iconv , _mem_cd_iconv )
"_iconv_close", referenced from:
_str_iconv in libidn.a(striconv.o)
"_iconv_open", referenced from:
_str_iconv in libidn.a(striconv.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
起初我以為是路徑問題,庫檔案沒導好。但是反覆檢查發現,不是這樣的。libidn.a這個靜態庫已經在Link Binary With Libraries裡。在網上查了很久的資料,最後在中午的時候想到other linker flags這個參數設定,於是找到發現這個參數設定是-all-load,將它刪除後,再運行無錯誤,問題解決。下午就查了些關於這個參數的一些資料。
包含靜態庫時候需要在Target的Other linker flags裡面加上值:-objC,-all_load,-force_load 對於64位機子和iPhone OS應用 解決方案是使用-all_load 或者 -force_load。 -all_load強迫連結器從它能看見的所有文檔中載入所有的對象檔案,甚至那些沒有OC代碼的文檔。 -force_load適用於Xcode3.2+版本,它允許finer得到文檔載入的控制。每一個-force_load操作必須跟著一個文檔路徑,文檔中的每一個對象檔案將會被載入。 -all_load就是會載入靜態庫檔案中的所有成員, -ObjC就是會載入靜態庫檔案中實現一個類或者分類的所有成員, -force_load(包的路徑)就是會載入指定路徑的靜態庫檔案中的所有成員。 舉個例子 當連結一個包含類別的OC靜態庫時候,將會得到一個運行時異常:"selector not recognized"。你需要設定Other Linker Flags的值為-ObjC就OK了
XCODE:<iOS>other linker flags