天天看點

錯誤1_clang: error: linker command failed with exit code 1 (use -v to see invocation)

做iOS開發有一段時間了.在開發中遇到了各種錯誤報告,在這裡總結一下希望對大家有幫助.

os開發這個錯誤一定少不了,現總結如下,一般這幾個方面的問題,如果不是那你真可麻煩了

1.引用出錯,把***.h弄成了.m,檢查一下你的所有引用;

2.再就是你引用第三方的庫,你添加檔案是系統沒有所第三方庫的.m檔案參入的編譯中去,你向項目添加檔案得注意了;

3.就是不小心添加的重複的類,向Entity之類,具體你可以看這裡http://stackoverflow.com/questions/2264455/iphone-duplicate-symbol-error;

4.有些frameworks沒有添加進來也會出現上面的問題;

而我遇到問題是第一種,出現這種問題還是因為不細心,希望大家在開發時自己多注意.

1.以如下錯誤為例,如果是多人開發,你同步完成後發現出現如下的錯誤。

<span style="font-size:12px;">Undefined symbols for architecture armv7:  
  "_OBJC_CLASS_$_BaiduMobStat", referenced from:  
      objc-class-ref in BaiduMobStatAppDelegate.o  
      objc-class-ref in MyPageLogViewController.o  
     (maybe you meant: _OBJC_CLASS_$_BaiduMobStatAppDelegate)  
ld: symbol(s) not found for architecture armv7  
clang: error: linker command failed with exit code 1 (use -v to see invocation)  </span>
           
<span style="font-size:12px;">
</span>
           

錯誤中出現了“MyPageLogViewController”這個類,你可以找到這個類的.m檔案, 檢視他的Target Membeship, 如下圖

錯誤1_clang: error: linker command failed with exit code 1 (use -v to see invocation)

如果沒有勾選上,點選勾選。然後編譯檢視。

2. 如果是新添加的第三方庫,且不是靜态庫

先重複第一步過程,然後找到 Build settings->Linking->Other Linker Flags

錯誤1_clang: error: linker command failed with exit code 1 (use -v to see invocation)

将此屬性修改成-all_load  或者 -ObjC ,這個視情況而定。總之可以多試幾次。

3.如果添加的是第三方靜态庫(.a檔案)

<span style="font-size:12px;">Undefined symbols for architecture armv7:  
  "_OBJC_CLASS_$_BaiduMobStat", referenced from:  
      objc-class-ref in BaiduMobStatAppDelegate.o  
      objc-class-ref in MyPageLogViewController.o  
     (maybe you meant: _OBJC_CLASS_$_BaiduMobStatAppDelegate)  
ld: symbol(s) not found for architecture armv7  
clang: error: linker command failed with exit code 1 (use -v to see invocation)  

</span>
           

在用到這個庫的所有檔案中都出現了錯誤, 如上 BaiduMobStatAppDelegate 類和 MyPageLogViewController類

這種情況就可能是這個靜态庫路徑混亂導緻的連結錯誤

解決方法:Build settings->Search Path->Library Search Paths  添加靜态庫的相應路徑。如下圖

錯誤1_clang: error: linker command failed with exit code 1 (use -v to see invocation)

如果上面的所有方法都不管用。你可以再試試一下幾個方法:

1,看看是不是有新添加的檔案跟之前檔案同名

2,錯誤資訊中出現了某個類的名字,去原檔案中看看#import了哪些第三方庫,把這些庫挨個注釋排除,找到出錯的那個庫,然後按照官方提供的步驟重新添加一遍。

以上内容通過網絡整理得到.

繼續閱讀