XCode - iOS - <OCMock/OCMock.h> 文件未找到
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25716580/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
XCode - iOS - <OCMock/OCMock.h> file not found
提问by Vince613
I Have an iOS application that I am trying to add OCMock to in order to better unit test it. I've followed the instruction on ocmock.org as well as instructions I've found in other places but still I cannot get my test code to compile.
我有一个 iOS 应用程序,我试图将 OCMock 添加到其中以便更好地对其进行单元测试。我已经按照 ocmock.org 上的说明以及我在其他地方找到的说明进行了操作,但仍然无法编译测试代码。
Here's what I've done
这是我所做的
Added the source code to my project directory
将源代码添加到我的项目目录中
Create the groups in my project to mimic my file system
在我的项目中创建组来模仿我的文件系统
I selected the option to add to my test targets so the framework was added appropriately as well as the Library Search Path
我选择了添加到我的测试目标的选项,以便适当地添加框架以及库搜索路径
Then I manually added the headers to the Header Search Path
然后我手动将标题添加到标题搜索路径
And added the -ObjC linker flag
并添加了 -ObjC 链接器标志
Then when I go to import the header file, I get the file not found error
然后当我去导入头文件时,我得到文件未找到错误
Any ideas what I am missing here???
任何想法我在这里缺少什么???
回答by Jeffery Thomas
You have the search path test/libraries/OCMock
. Then you have #import <OCMock/OCMock.h>
.
你有搜索路径test/libraries/OCMock
。那么你有#import <OCMock/OCMock.h>
。
This fails because there is no file test/libraries/OCMock/OCMock/OCMock.h
.
这将失败,因为没有文件test/libraries/OCMock/OCMock/OCMock.h
。
You use the search path test/libraries
, or you can create a prefix directory to hold OCMock
and have the search path point at that.
您可以使用搜索路径test/libraries
,或者您可以创建一个前缀目录来保存OCMock
并让搜索路径指向该目录。
I generally have a directory with the library name and version number before the actually directory.
我通常在实际目录之前有一个包含库名称和版本号的目录。
The directory test/libraries/OCMock-X.X.X
could contain the OCMock
directory. That way the search path still be more specific: test/libraries/OCMock-X.X.X
and you still use OCMock/OCMock.h
as the include.
目录test/libraries/OCMock-X.X.X
可以包含OCMock
目录。这样搜索路径仍然更具体:test/libraries/OCMock-X.X.X
并且您仍然使用OCMock/OCMock.h
作为包含。
回答by janineanne
One more thing to check, for anyone else having this problem - I copied OCMock from one project to another and everything lookedright, but it wasn't finding the include file. It turned out that even though I had the right groups in Xcode, the files had all been dumped into one directory. I needed to create folders on disk and associate them with the groups in Xcode. The accepted answer here clued me in to what was wrong (though as is often the case, in hindsight it should have been obvious).
还有一件事要检查,对于其他遇到此问题的人 - 我将 OCMock 从一个项目复制到另一个项目,一切看起来都正确,但没有找到包含文件。结果是,即使我在 Xcode 中设置了正确的组,文件也已全部转储到一个目录中。我需要在磁盘上创建文件夹并将它们与 Xcode 中的组相关联。这里接受的答案让我知道出了什么问题(尽管通常情况下,事后看来它应该是显而易见的)。