ios Xcode 找不到头文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33691707/
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 can't find header file
提问by Yucel Bayram
I am trying to make a framework for my project. Into my framework I added the path of my header files to target>Build Settings>header-search path. After that I added this framework to my project by Build Phases>Link Binary With Libraries.
我正在尝试为我的项目制作一个框架。在我的框架中,我将头文件的路径添加到target>Build Settings>header-search path。之后,我通过Build Phases>Link Binary With Libraries将此框架添加到我的项目中。
When I want to import the header file which I included in my framework, I get a .h file not founderror. Is what I'm trying to do possible? Or am I missing anything?
当我想导入包含在框架中的头文件时,出现.h 文件未找到错误。我正在尝试做的可能吗?还是我错过了什么?
I created framework like that;
我创建了这样的框架;
Opened new project as iOS>Framework&Library>Cocoa Touch Framework I didn't add any class, i just added header search path and library search path and linker flags. I don't think i did a mistake in this part because we do it in every project but first time i m doing this for framework. Then i pressed run and get my framework from Products.
打开新项目为 iOS>Framework&Library>Cocoa Touch Framework 我没有添加任何类,我只是添加了标题搜索路径和库搜索路径以及链接器标志。我不认为我在这部分犯了错误,因为我们在每个项目中都这样做,但我第一次为框架这样做。然后我按下运行并从产品中获取我的框架。
I opened my project and added framework Build Phases>Link Binary With Libraries. I m able to import header file of framework like #import <myframework/framework.h>
After this i added framework also General>Embedded Binaries. Everything look normal but i cannot add headers to my project which i included to my framework with header search path. I have to use header search path because there is tons of headers, i cannot add all of them to my Xcode.
我打开了我的项目并添加了框架 Build Phases>Link Binary With Libraries。我可以导入框架的头文件,例如#import <myframework/framework.h>
在此之后,我还添加了框架 General>Embedded Binaries。一切看起来都很正常,但我无法将标题添加到我的项目中,我使用标题搜索路径将其包含在我的框架中。我必须使用标头搜索路径,因为有大量标头,我无法将所有标头都添加到我的 Xcode 中。
回答by Meghs Dhameliya
回答by Caleb
Everything look normal but i cannot add headers to my project which i included to my framework with header search path.
一切看起来都很正常,但我无法将标题添加到我的项目中,我使用标题搜索路径将其包含在我的框架中。
It sounds as though you're expecting all the headers that can be found at the path specified by your header search path will become part of your framework, so that if there's a header named SomeHeader.h
in your search path, it will be built into your framework and you'll be able to import it into client projects like:
听起来好像您期望在您的标头搜索路径指定的路径中可以找到的所有标头都将成为您框架的一部分,因此如果SomeHeader.h
您的搜索路径中有一个标头,它将被内置到您的框架中您将能够将其导入到客户端项目中,例如:
#import <MyFramework/SomeHeader.h>
But that's not the case at all. If you want your framework to provide SomeHeader.h
, you need to add that file to the project and, as Meghs Dhameliya already pointed out, you need to specify SomeHeader.h
in the Public Headers portion of the Headers build phase. This will make Xcode copy the header file into the framework so that clients of the framework can import the header file. It's not clear that that's what you really want, though... in comments you wrote:
但事实并非如此。如果您希望您的框架提供SomeHeader.h
,则需要将该文件添加到项目中,并且正如 Meghs Dhameliya 已经指出的那样,您需要SomeHeader.h
在 Headers 构建阶段的 Public Headers 部分中指定。这将使 Xcode 将头文件复制到框架中,以便框架的客户端可以导入头文件。目前尚不清楚这是否是您真正想要的,但是……在您写的评论中:
There is a lot of headers in another path. I have to use header search path unfortunately. Kind of company rule.
另一条路径中有很多标题。不幸的是,我必须使用标题搜索路径。公司规定的那种。
So it sounds like all projects in your company specify the same header search path so that they have access to these header files. If that's true, then there's no reason for projects to need to #import
them from your framework, but in that case it's not clear what the actual problem is. Or, perhaps you're creating the framework so that client projects can get the headers from your framework instead of having to reference the header search path. In that case, you will need to add those headers to the project and specify them as described above.
所以听起来您公司中的所有项目都指定了相同的头搜索路径,以便他们可以访问这些头文件。如果这是真的,那么项目就没有理由需要#import
从您的框架中获取它们,但在这种情况下,尚不清楚实际问题是什么。或者,您可能正在创建框架,以便客户端项目可以从您的框架中获取标头,而不必引用标头搜索路径。在这种情况下,您需要将这些标头添加到项目中并按上述方式指定它们。