ld: warning: directory not found for option 错误

本文转载于:https://blog.csdn.net/zhyl8157121/article/details/48844573

问题及解决方法

简单来说,这个问题分两个方面。

  • 错误如下,这表示是查询 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

删除里面的路径

解释

简单说一下 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 <> 的错误这就需要配置一些搜索路径。

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》


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值