Include of non-modular header inside framework module
Asked Answered
L

24

204

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.

Loredo answered 5/1, 2015 at 9:22 Comment(0)
D
265

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

Dann answered 22/6, 2016 at 4:15 Comment(3)
That helped me to include Objective C code into a Swift framework, thanks!Verruca
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.Bloomy
If importing the library into a mix of swift/objc, need to insure the bridging header is public too. Mistake i made!Knapweed
S
212

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

Sarilda answered 17/2, 2015 at 0:6 Comment(4)
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.Pruett
But what if they're system includes, like /usr/include/libproc.h?Tocology
Could you please explain what is the impact of changing: Allow Non-modular Includes in Framework ModulesCess
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.Tocology
T
87

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.

Tovatovar answered 7/6, 2015 at 18:48 Comment(3)
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.Ptolemaist
Oops, no it didn't. Discovered it was broken after I cleaned my project :-/Ptolemaist
I can not find any 'ambiguous reference' warnings whatsoever. What are the drawbacks of leaving it set to YES?Kaufmann
L
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

Lycia answered 13/4, 2017 at 9:14 Comment(3)
This happens in particular when you duplicate an existing public header, the duplicated header membership is changed to "project"Doud
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.Lycia
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!Shadchan
T
42

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

Tonsillotomy answered 12/2, 2020 at 11:25 Comment(1)
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.Isentropic
M
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.

Monaco answered 27/4, 2016 at 21:52 Comment(2)
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.Felten
Same here, fixed my issue!Kerch
T
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).

Trinatte answered 20/7, 2015 at 13:10 Comment(0)
A
17

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.

Ambidexter answered 5/6, 2018 at 10:8 Comment(1)
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?Institutionalism
M
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
Mitten answered 19/8, 2017 at 22:37 Comment(0)
P
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.

Purchase answered 16/8, 2017 at 4:52 Comment(0)
E
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>.

Eleemosynary answered 28/11, 2017 at 19:21 Comment(1)
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 <https://mcmap.net/q/126842/-include-of-non-modular-header-inside-framework-modulePau
R
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.

Radioscopy answered 20/5, 2016 at 17:14 Comment(0)
O
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.

Osugi answered 25/8, 2019 at 14:52 Comment(3)
I can confirm this was my problem too.Clef
I had this problem with PersonalizedAdConsent and this fixed it. Thanks!Leopard
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.Vardhamana
P
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
Pau answered 7/6, 2021 at 9:45 Comment(3)
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.Mankind
@Pau Can you please explain in detail with an example, how you did it? I am having similar issue.Cameleer
@JoseServet Can you also please look at my above comment and explain in detail with an example, how you did it?Cameleer
H
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"
Huskey answered 22/6, 2021 at 14:38 Comment(0)
P
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.

Pseudoscope answered 15/6, 2016 at 21:37 Comment(0)
L
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

Longitudinal answered 10/5, 2019 at 8:6 Comment(0)
D
1

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

Delcine answered 8/4, 2020 at 4:14 Comment(0)
L
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!

Lowson answered 2/10, 2020 at 7:9 Comment(0)
G
1

For Flutter developers, a

flutter clean fluter pub get and pod install

solved this for me

Gad answered 17/8, 2023 at 16:3 Comment(0)
I
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.

Iodine answered 19/8, 2018 at 17:40 Comment(0)
C
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.

Crapulent answered 20/11, 2018 at 13:46 Comment(0)
T
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

Tamtam answered 24/2, 2021 at 9:3 Comment(0)
S
-11

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

Sadiras answered 17/5, 2018 at 21:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.