objective-c 在框架模块中包含非模块化头文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27776497/
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
Include of non-modular header inside framework module
提问by Dev
I am using Xcode 6,
我正在使用 Xcode 6,
1) Firstly I am creating a dynamic library (CoreLibrary). This library contain RequestPoster.h file.
1)首先,我正在创建一个动态库(CoreLibrary)。该库包含 RequestPoster.h 文件。
2) Then I create a Cocoa Touch Framework and added this dynamic library (CoreLibrary).
2)然后我创建了一个 Cocoa Touch Framework 并添加了这个动态库(CoreLibrary)。
3) Then this framework is add on my project and it gives error in RequestPoster.h file (CoreLibrary).
3) 然后这个框架被添加到我的项目中,它在 RequestPoster.h 文件 (CoreLibrary) 中给出了错误。
Error : Include of non-modular header inside framework module class :
错误:在框架模块类中包含非模块化标头:
ifaddrs.h, arpa/inet.h, sys/types.h>
ifaddrs.h、arpa/inet.h、sys/types.h>
These file not found in the project.
在项目中找不到这些文件。
回答by bcattle
Try going Build Settings under "Target" and set "Allow Non-modular Includes in Framework Modules" to YES.
尝试转到“目标”下的“构建设置”并将“允许非模块化包含在框架模块中”设置为“是”。
The real answer is that the location of the imports needs to be changed by the library owner. Those files ifaddrs.h, arpa/inet.h, sys/types.h are getting imported in a .h file in a framework, which Xcode doesn't like. The library maintainer should move them to a .m file. See for example this issue on GitHub, where AFNetworking fixed the same problem: https://github.com/AFNetworking/AFNetworking/issues/2205
真正的答案是导入的位置需要由库所有者更改。这些文件 ifaddrs.h、arpa/inet.h、sys/types.h 被导入到框架中的 .h 文件中,Xcode 不喜欢。库维护者应该将它们移动到 .m 文件。例如,请参阅 GitHub 上的此问题,其中 AFNetworking 修复了相同的问题:https: //github.com/AFNetworking/AFNetworking/issues/2205
回答by Long Pham
Make sure the header files are publicly available as part of the framework's public headers.
确保头文件作为框架公共头文件的一部分公开可用。
Goto Framework -> Target -> Build Phases and drag to move the relevant header files from Project to Public. Hope that helps!
转到 Framework -> Target -> Build Phases 并拖动以将相关头文件从 Project 移动到 Public。希望有帮助!


回答by revprez
You can set Allow Non-modular includes in Framework Modulesin Build Settings for the affected target to YES. This is the build setting you need to edit:
您可以将受影响目标的构建设置中的“允许非模块化包含在框架模块中”设置为“是”。这是您需要编辑的构建设置:
NOTE: You should use this feature to uncover the underlying error, which I have found to be frequently caused by duplication of angle-bracketed global includes in files with some dependent relationship, i.e.:
注意:您应该使用此功能来发现潜在的错误,我发现这经常是由具有某些依赖关系的文件中的尖括号全局包含重复引起的,即:
#import <Foo/Bar.h> // referred to in two or more dependent files
If setting Allow Non-modular includes in Frame Modulesto YESresults in a set of "X is an ambiguous reference" errors or something of the sort, you should be able to track down the offending duplicate(s) and eliminate them. After you've cleaned up your code, set Allow Non-modular includes in Frame Modulesback to NO.
如果将Allow Non-modular includes in Frame Modules 设置为YES导致一组“X 是一个不明确的引用”错误或类似的错误,您应该能够追踪有问题的重复项并消除它们。清理完代码后,将Allow Non-modular includes in Frame Modules 设置回NO。
回答by Saad
I had the same problem and solve it by just making header file public.
![[problem]](/static/img/viewimg.png)
我遇到了同样的问题,只是通过公开头文件来解决它。
![[问题]](/static/img/viewimg.png)
If you are working on multiple modules in your project. Then your header file needs to be public to be used in other parts of projects. What you need is to select that header file, and in project Utilities view. Change the file from Project/Private to Public. See image below:
如果您正在处理项目中的多个模块。然后你的头文件需要公开才能在项目的其他部分使用。您需要的是选择该头文件,并在项目实用程序视图中。将文件从项目/私人更改为公共。见下图:
回答by John Bushnell
"Include of non-modular header inside framework module"
“在框架模块中包含非模块化头文件”
When you get this error the solution in some circumstances can be to simply to mark the file you're trying to import as "public" in the file inspector "Target Membership". The default is "Project", and when set this way it can cause this error. That was the case with me when trying to import Google Analytic's headers into a framework, for example.
当您收到此错误时,在某些情况下的解决方案可以是简单地在文件检查器“目标成员资格”中将您尝试导入的文件标记为“公共”。默认值为“Project”,当以这种方式设置时,可能会导致此错误。例如,当我尝试将 Google Analytic 的标头导入框架时就是这种情况。
回答by strangetimes
Actually an easier way to fix this is to move the #importstatement to the top of the .mfile instead (instead of having it in your .hheader file). This way it won't complain that it's including a non-modular header file. I had this problem where Allow non-module includesset to YESdid NOTwork for me, so by moving it to the implementation file, it stopped complaining. This is in fact the preferred way of importing and including header files anyway. Once you've done this, setting this back to NOshould work.
实际上,解决此问题的更简单方法是将#import语句移至.m文件顶部(而不是将其放在.h头文件中)。这样它就不会抱怨它包含一个非模块化的头文件。我有这个问题,即Allow non-module includes设定为YES没有不对我来说有效,所以通过其移动到实现文件,它停止抱怨。这实际上是导入和包含头文件的首选方式。完成此操作后,将其设置回NO应该可以工作。
Ideally we should try and aim to have Allow non-module includesset to NO. Setting this to YESin most cases means you're doing something wrong. The setting translates to "Allow importing random header files on disk that aren't otherwise part of the module". This applies to a very few use cases in practice, and so this setting should always be NO(i.e. the default value).
理想情况下,我们应该尝试并瞄准Allow non-module includes设置为NO。YES在大多数情况下将此设置为意味着您做错了什么。该设置转换为“允许在磁盘上导入不属于模块的随机头文件”。这适用于实践中的极少数用例,因此该设置应始终为NO(即默认值)。
回答by Mert Celik
In case if you are developing your own framework:
如果您正在开发自己的框架:
WHY is this happening?
为什么会这样?
If any of the public header files you have mentioned in your module.modulemaphave import statements that are notmentioned in modulemap, this will give you the error. Since it tries to import some header that is not declared as modular (in module.modulemap), it breaks the modularity of the framework.
如果您在module.modulemap 中提到的任何公共头文件具有在modulemap中未提到的导入语句,则会出现错误。由于它试图导入一些未声明为模块化的头文件(在 module.modulemap 中),它破坏了框架的模块化。
HOW can I fix it?
我该如何解决?
Just include the header that gave the error to your module.modulemap and build again!
只需将导致错误的标头包含在 module.modulemap 中,然后再次构建!
WHY NOT just set allow non-modular to YES?
为什么不只是将允许非模块化设置为是?
Because it's not really a solution here, with that you tell your project "this framework was supposed to be modular but it's not. Use it somehow, I don't care." This doesn't fix your library's modularity problem.
因为这不是真正的解决方案,所以你告诉你的项目“这个框架应该是模块化的,但事实并非如此。以某种方式使用它,我不在乎。” 这并不能解决您的库的模块化问题。
For more information check this blog postor refer to clang docs.
回答by k06a
If you need this for CocoaPods targets add this lines in Podfile:
如果您需要为 CocoaPods 目标添加此行Podfile:
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
target.build_settings(config.name)['CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES'] = 'YES'
end
end
end
回答by Misha Karpenko
If you see this error in an umbrella headerwhen building a dynamic framework, make sure you import your file as:
如果在构建动态框架时在伞头中看到此错误,请确保将文件导入为:
#import "MyFile.h"
#import "MyFile.h"
and notas #import <MyFramework/MyFile.h>.
和不作为#import <MyFramework/MyFile.h>。
回答by u8198804
the same problem make crazy.finally, i find put the 'import xxx.h' in implementation instead of interface can fix the problem.And if you use Cocoapods to manager your project.you can add
同样的问题让人抓狂。最后,我发现将“import xxx.h”放在实现中而不是接口可以解决问题。如果您使用 Cocoapods 来管理您的项目。您可以添加
s.user_target_xcconfig = { 'CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES' => 'YES' }
s.user_target_xcconfig = { 'CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES' => 'YES' }
in your 'xxx.podspec' file.
在您的“xxx.podspec”文件中。

