【解決方法】ld: warning: directory not found for option

IOS開發過程中這個問題很容易搞的很迷糊。今天來掰扯掰扯。

問題及解決方法

簡單來說,這個問題分兩個方面。

  • 錯誤如下,這表示是查詢 Library 的時候出現的異常。

"directory not found for option '-L/..."

解決方法:

依次 Project -> targets -> Build Setting -> Library Search Paths

刪除裏面的路徑

  • 錯誤如下, 這表示是查詢 Framework 的時候出現的異常。

"directory not found for option '-F/..."

解決方法:

依次 Project -> targets -> Build Setting -> Framework Search Paths

刪除裏面的路徑

OK,搞定。

上面已經解決問題,如果還想了解更多,可以繼續向下看。

解釋

簡單說一下 Library Search PathsFramework Search Paths

Framework Search Paths

官方文檔 能查到的解釋是:

Locating Frameworks in Non-Standard Directories

If your project links to frameworks that are not included in any of the standard locations, you must explicitly specify the location of that framework before Xcode can locate its header files. To specify the location of such a framework, add the directory containing the framework to the “Framework Search Paths” option of your Xcode project. Xcode passes this list of directories to the compiler and linker, which both use the list to search for the framework resources.

Note: The standard locations for frameworks are the /System/Library/Frameworks directory and the /Library/Frameworks directory on the local system.

大意是說,如果你引用的 Frameworks 沒有在標準位置(standard locations),那麼,你需要在工程的配置文件裏設置 “Framework Search Paths”, 用來爲編譯器(compiler)和連接器(linker)指定搜索路徑。

Library Search Paths

至於 “Library Search Paths”,沒有查到像樣的官方文檔,不過想想內容應該是差不多的,不過一個用來搜索Framework,一個用來搜索Library

話雖然是這麼說,但是什麼是Library,什麼是Framework,還是很蒙圈。

不過,搜索到了一些博客,來說明這個問題,現引用在下方。

引用

iOS開發中的Search Paths設置

在 iOS 開發中經常遇到一些關於路徑的設置,比如引入了百度地圖的 SDK,項目拷貝到其他的電腦上或者多人同時開發的時候容易報 Library Not Found 的錯誤,或者是引入第三方庫比如 ASIHttpRequest/RETableView 經常報 #include <> 的錯誤這就需要配置一些搜索路徑。

Framework/Library Search Paths

1、Framework Search Paths

附加到項目中的framework(.framework bundles)的搜索路徑,在iOS開發中使用的不是特別多,通常對於iOS的開發來說一般使用系統內置的framework。

2、Library Search Paths

附加到項目中的第三方Library(.a files)的搜索路徑,Xcode會自動設置拖拽到Xcode中的.a文件的路徑,爲了便於移植或者是多人協作開發一般會手動設置。

比如對於設置百度的地圖的SDK,我們會設置如下:

$(SRCROOT)/../libs/Release$(EFFECTIVE_PLATFORM_NAME),其中 $(SRCROOT)宏代表您的工程文件目錄,$(EFFECTIVE_PLATFORM_NAME)宏代表當前配置是 OS 還是 simulator

Header Search Path

1、C/C++頭文件引用

在C/C++中,include是變異指令,在編譯時,編譯器會將相對路徑替換成絕對路徑,因此,頭文件的絕對路徑等同於搜索路徑+相對路徑。

(1) #include <iostream.h>:引用編譯器的類庫路徑下的頭文件

(2)#include "hello.h":引用工程目錄的相對路徑的頭文件

2、(User) Header Search Path

(1)Header Search Path指的是頭文件的搜索路徑。

(2)User Header Search Paths指的是用戶自定義的頭文件的搜索路徑

3、Always Search User Paths

如果設置了Always Search User PathsYES,編譯器會優先搜索 User Header Search Paths 配置的路徑,在這種情況下 #include <string.h>, User Header Search Paths 搜索目錄下面的文件會覆蓋系統的頭文件。

參考資料

  1. 《iOS開發中的Search Paths設置》
  2. 《iOS: Clarify different Search Paths》
  3. 《iOS Developer Library - Including Frameworks》
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章