1. 程式人生 > >【解決方法】ld: warning: directory not found for option

【解決方法】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 搜尋目錄下面的檔案會覆蓋系統的標頭檔案。

參考資料