212

I am using Xcode 6,

1) Firstly I am creating a dynamic library (CoreLibrary). This library contain RequestPoster.h file.

2) Then I create a Cocoa Touch Framework and added this dynamic library (CoreLibrary).

3) 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.

26 Answers 26

267

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.

Screenshot

Sign up to request clarification or add additional context in comments.

4 Comments

That helped me to include Objective C code into a Swift framework, thanks!
You can also make this change to Target Membership from Project to Public in your file by using the File Inspector window on the right of XCode's main screen.
If importing the library into a mix of swift/objc, need to insure the bridging header is public too. Mistake i made!
I have set the headers to public, but still get this error. What could be the problem?
224

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

5 Comments

In case the header with error is using a type from the imported headers, what is recommended? For eg, if header module.h in module declares a function taking a parameter of type ifaddrs, they are bound to import ifaddrs.h.
But what if they're system includes, like /usr/include/libproc.h?
Could you please explain what is the impact of changing: Allow Non-modular Includes in Framework Modules
I think perhaps the best answer would involve making it a modular header, rather than basically silencing this error. I can easily imagine Apple removing the option to allow non-modular headers in a module.
AFNetworking issue link is dead :/
95

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:

Build Settings item 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.

3 Comments

Ok, it was the angle-brackets causing the problem! I had this problem with a CocoaPods import and fixed it by changing the import to use quotes instead of angle brackets.
Oops, no it didn't. Discovered it was broken after I cleaned my project :-/
I can not find any 'ambiguous reference' warnings whatsoever. What are the drawbacks of leaving it set to YES?
54

I had the same problem and solve it by just making header file public. [problem]

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:

Changing header file scope

3 Comments

This happens in particular when you duplicate an existing public header, the duplicated header membership is changed to "project"
no it's not compulsory for the duplication thing. It may occur due to different cases for example if you import some project as library completely in your project and then you try to modify the private classes. You know the header file and write it but the access is not public to all project.
This worked for me when trying to access the C structs defined in a header I was building for a local Metal library. I needed to make I public in the Metal Library and then import it into the framework header to use the types in the framework. Thanks!
46

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

1 Comment

Thanks a lot, this helped me figure it out. I had a vendored framework that was causing this and I had no chance in getting an updated version of it. -Wno-error=non-modular-include-in-framework-module helped to fix it.
32

"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.

2 Comments

This answer helped me much in my similar problem. I didn’t know framework header files can be added to the target. In application projects, headers are never part of a target.
Same here, fixed my issue!
23

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).

Comments

19

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.

1 Comment

how did you set it up the module.modulemap with cocoa projects framework, I tried to let my library be able to work with Swift-only projects, but because one dependency of the library, the module.modulemap is not working, the cocoapod is autogenerating the modulemap, but it seems to not work, have you faced something similar?
11

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

Comments

9

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>.

1 Comment

This helped to build the framework itself, but later I faced the same error in unit-tests, because auto-generated MyFramework-Swift.h contained #import <MyFramework/MyFramework.h>. I solved it by renaming public headers directory <stackoverflow.com/a/67869384/10380092
9

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.

Comments

6

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.

Comments

5

enter image description here

To solve the "Include of non-modular header inside framework module 'firebase_crashlytics.Crashlytics_Platform'" error, follow these steps:

  1. Open Xcode.
  2. Click on Runner in your project navigator.
  3. Go to the Build Settings tab.
  4. In the search bar, type Apple Clang - Language - Modules.
  5. Look for the option

allow non-modular includes in framework modules.

  1. Set this option to

Yes

.

This should resolve the error.

1 Comment

im using flutter and this worked for me after updating to macos sequoia lol
4

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.

3 Comments

I can confirm this was my problem too.
I had this problem with PersonalizedAdConsent and this fixed it. Thanks!
Almost this one too. I had this issue in my Tests target, weirdly, the Header Search Paths was including $(SRCROOT)/Pods, recursive. Which was causing the issue.
4

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

3 Comments

I had this problem with an Xcode project which contained nested subprojects. I was able to compile every subproject individually, but the main project failed to compile with the error. Renaming the public headers folder worked for me. I guess some of the subprojects are not correctly configured, but I haven't found the wrong setting yet. At least this way I can compile the main project.
@alexander.cpp Can you please explain in detail with an example, how you did it? I am having similar issue.
@JoseServet Can you also please look at my above comment and explain in detail with an example, how you did it?
3

This just worked for me, but if after that there was still a long error and you're using flutterfire, just make sure you're using the latest version of it.

This just worked for me

Comments

2

try @import FrameworkName instead of #import "FrameworkName.h"

Comments

2

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"

Comments

2

For Flutter developers, a

flutter clean fluter pub get and pod install

solved this for me

Comments

1

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.

Comments

1

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.

enter image description here

Comments

1

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!

Comments

0

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.

Comments

0

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 be CoreLibrary.framework) & Delete Modules folder.

  • Clean and Re Build the app, it will solve the problem.

Comments

0

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

Comments

-11

I was able to clear dozens of these errors by using Git clean. Here's the command: git clean -dffx && git reset --hard

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.