Include of non-modular header inside framework module
Objective CCocoa TouchObjective C Problem Overview
I am using Xcode 6,
-
Firstly I am creating a dynamic library (CoreLibrary). This library contain RequestPoster.h file.
-
Then I create a Cocoa Touch Framework and added this dynamic library (CoreLibrary).
-
Then this framework is add on my project and it gives error in RequestPoster.h file (CoreLibrary).
Error : Include of non-modular header inside framework module class :
ifaddrs.h, arpa/inet.h, sys/types.h>
These file not found in the project.
Objective C Solutions
Solution 1 - Objective C
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!
Solution 2 - Objective C
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
Solution 3 - Objective C
You can set Allow Non-modular includes in Framework Modules in 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 Modules to YES results 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 Modules back to NO.
Solution 4 - Objective C
I had the same problem and solve it by just making header file public.
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:
Solution 5 - Objective C
"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.
Solution 6 - Objective C
Allow Non-modular Includes in Framework Modules
only work in objc code. not work in swift.
After a period of research, I found that swift can pass warning parameter to clang, so set OTHER_SWIFT_FLAGS
to -Xcc -Wno-error=non-modular-include-in-framework-module
inhibit swift import error.
just for someone who have same problem
Solution 7 - Objective C
Actually an easier way to fix this is to move the #import
statement to the top of the .m
file instead (instead of having it in your .h
header file). This way it won't complain that it's including a non-modular header file. I had this problem where Allow non-module includes
set to YES
did NOT work 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 NO
should work.
Ideally we should try and aim to have Allow non-module includes
set to NO
. Setting this to YES
in 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).
Solution 8 - Objective C
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.modulemap have import statements that are not mentioned 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.
HOW can I fix it?
Just include the header that gave the error to your module.modulemap and build again!
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 archived blog post or refer to clang docs.
Solution 9 - Objective C
If you need this for CocoaPods targets add this lines in 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
Solution 10 - Objective C
If you see this error in an umbrella header when building a dynamic framework, make sure you import your file as:
#import "MyFile.h"
and not as #import <MyFramework/MyFile.h>
.
Solution 11 - Objective C
The same problem made me crazy. Finally, I put the import xxx.h
in implementation instead of interface can fix the problem. And if you use Cocoapods to manage your project, you can add:
s.user_target_xcconfig = { 'CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES' => 'YES' }
in your .podspec
file.
Solution 12 - Objective C
I had the same issue and nothing from above helped me. So I hope my answer will be helpful for somebody. In my case the problem was in ALWAYS_SEARCH_USER_PATHS setting. When it was set to NO project built and worked ok. But as far as one of the pod required it to be set to YES I was receiving an error
> Include of non-modular header inside framework module
After couple cups of coffee and all day researching I found out that according to known issues of Xcode 7.1 Beta 2 release notes:
> • If you get an error stating "Include of non-modular header inside > framework module" for a framework that previously compiled, make sure > the "Always Search User Paths" build setting is set to "No". The > default is "Yes" only for legacy reasons. (22784786)
I was using XCode 7.3 though, but seems like this bug hasn't been fixed yet.
Solution 13 - Objective C
I had this error in umbrella header of a dynamic framework (mix of Swift and Objective-C). The public headers directory had the same name as the framework itself. Renaming it to PublicHeaders did the trick (headers are still included as #import <FrameworkName/Header.h>
).
My check-list for this case:
- set
Target Membership
=Public
for umbrella header and all headers imported from it - set
Enable Modules (C and Objective-C)
=YES
- ensure public headers are located in a directory which name is different from the name of the framework
Solution 14 - Objective C
I came across this issue as well and originally thought it was a CocoaPods issue, but it was an issue in the apps build settings where someone (probably me) had set ${PODS_ROOT}
in Header Search Paths and set it to be a recursive
search. This was allowing it to find headers that were not intended to be used when building the app. Once I set this to use non-recursive
everything was fine. using recursive
search is a terrible hack to try to find the proper headers. Lesson learned.
Solution 15 - Objective C
This was kind of an annoying issue for me. No suggestions seemed to help my particular case, since I needed to include the "non-modular" headers in my individual file header file. The work around I used was sticking the import call in the prefix header file.
Solution 16 - Objective C
In my case I forgot to add .h and .m file in .podspecs file's "s.source_files" section.
after adding this in it work fine.
Solution 17 - Objective C
In my case, as every header you expose publicly is seen by your umbrella header;
The fix was to simply use name-only, like:
#import "my-public-file.h"
Instead of:
#import "my-path/added-to/header-search-paths/for/my-public-file.h"
Solution 18 - Objective C
I ended up moving the Umbrella Header to bottom of the Headers list after checking the above solutions, and that worked in Xcode 9.3.
Solution 19 - Objective C
I solved it removing Modules
folder from the framework.
-
Browse to your framework location which is present in the App Project using finder
-
Go inside
Test.framework
folder (In the above case it will beCoreLibrary.framework
) & DeleteModules
folder. -
Clean and Re Build the app, it will solve the problem.
Solution 20 - Objective C
try @import FrameworkName
instead of #import "FrameworkName.h"
Solution 21 - Objective C
I was having a similar problem! When running my app target, everything was working fine, but when changing to test target and trying to run the tests, "Include of non-modular header inside framework module" error showed up. I tried all the solutions posted here but none of them worked. At the end I scrolled over all build settings and for each one that was related to headers I read the description.
Switching USE_HEADERMAP
to NO
did the trick!
I hope anyone could find this helpful!
Solution 22 - Objective C
I had this problem when I added Swift source code to an existing ObjC static framework (dynamic framework with Mach-O type "Static Library").
The fix was setting CLANG_ENABLE_MODULES
("Enable Modules" in build settings) to YES
Solution 23 - Objective C
I was able to clear dozens of these errors by using Git clean. Here's the command: git clean -dffx && git reset --hard