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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhyl8157121/article/details/48844573

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》

猜你喜欢

转载自blog.csdn.net/zhyl8157121/article/details/48844573