問題及解決方法
簡單來說,這個問題分兩個方面。
- 錯誤如下,這表示是查詢 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 Paths 和 Framework 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 <>
的錯誤這就需要配置一些搜索路徑。<a name="t6" style="box-sizing: border-box; background: transparent; color: rgb(79, 161, 219); text-decoration: none; margin: 0px; padding: 0px; font-weight: 400; outline: 0px;"></a>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<a name="t7" style="box-sizing: border-box; background: transparent; color: rgb(79, 161, 219); text-decoration: none; margin: 0px; padding: 0px; font-weight: 400; outline: 0px;"></a>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 Paths
為YES
,編譯器會優先搜索User Header Search Paths
配置的路徑,在>這種情況下#include <string.h>
,User Header Search Paths
搜索目錄下面的文件會覆蓋系統的頭文件。
參考資料
- 《iOS開發中的Search Paths設置》
- 《iOS: Clarify different Search Paths》
- 《iOS Developer Library - Including Frameworks》
文章參考自:
Bottle's Blog
感謝作者