鏈接常見錯誤linker command failed with exit code 1 (use -v to see invocation)

這種問題,一般出如今添加第三方庫文件或者多人開發時。html

這種問題通常是找不到文件而致使的連接錯誤。 咱們能夠從以下幾個方面着手排查。ui

 

1.以以下錯誤爲例,若是是多人開發,你同步完成後發現出現以下的錯誤。spa

 

[html]  view plain  copy
 
  1. Undefined symbols for architecture armv7:  
  2.   "_OBJC_CLASS_$_MyPageLogViewController", referenced from:  
  3.       objc-class-ref in BaiduMobStatAppDelegate.o  
  4. ld: symbol(s) not found for architecture armv7  
  5. clang: error: linker command failed with exit code 1 (use -v to see invocation)  


錯誤中出現了「MyPageLogViewController」這個類,你能夠找到這個類的.m文件, 查看他的Target Membeship, 以下圖.net

 

若是沒有勾選上,點擊勾選。而後編譯查看。code

 

2. 若是是新添加的第三方庫,且不是靜態庫xml

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

將此屬性修改爲-all_load  或者 -ObjC ,這個視狀況而定。總之能夠多試幾回。blog

 

3.若是添加的是第三方靜態庫(.a文件)ip

 

[html]  view plain  copy
 
  1. Undefined symbols for architecture armv7:  
  2.   "_OBJC_CLASS_$_BaiduMobStat", referenced from:  
  3.       objc-class-ref in BaiduMobStatAppDelegate.o  
  4.       objc-class-ref in MyPageLogViewController.o  
  5.      (maybe you meant: _OBJC_CLASS_$_BaiduMobStatAppDelegate)  
  6. ld: symbol(s) not found for architecture armv7  
  7. clang: error: linker command failed with exit code 1 (use -v to see invocation)  


在用到這個庫的全部文件中都出現了錯誤, 如上 BaiduMobStatAppDelegate 類和 MyPageLogViewController類開發

 

這種狀況就多是這個靜態庫路徑混亂致使的連接錯誤

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

 

若是上面的全部方法都無論用。你能夠再試試一下幾個方法:

1,看看是否是有新添加的文件跟以前文件同名

2,錯誤信息中出現了某個類的名字,去原文件中看看#import了哪些第三方庫,把這些庫挨個註釋排除,找到出錯的那個庫,而後按照官方提供的步驟從新添加一遍。

相關文章
相關標籤/搜索