19

I’m writing a dynamic Framework (Proto.framework) for OS X in Swift. I want to include code from a static library (libstat.a) which is written in Objective C. Here’s what I’ve got:

// Dynamic.swift in Proto.framework class Dynamic { func doSomethingWithStat() { Stat().statThing() } } // Stat.h in libstat.a static library @interface Stat : NSObject - (void)statThing; @end // Stat.m @implementation Stat - (void)statThing { NSLog(@"OK"); } @end 

In my target for Proto.framework, I have linked it to libstat.a. When I try to build Proto, naturally it doesn’t compile because it can’t find the definition for Stat().statThing(). It doesn’t know the symbols for my static library. How do I tell it about that?

For applications, I’d use a bridging header and do #import <Stat/Stat.h>. But the compiler errors out and tells me Bridging headers aren’t allowed in frameworks. OK.

So I include it in my “umbrella header” (Proto.h) but that tells me error: include of non-modular header inside framework module. OK.

Making my Stat library target Defines module: YES doesn’t seem to change the error even after a clean build. So I’m not sure how to do this.

Can someone point me in the right direction?

3
  • 1
    Have you managed to figure this out eventually? I am struggling with the same issue. Commented Aug 20, 2015 at 9:33
  • Same problem here. Any solution? Commented Oct 23, 2015 at 13:55
  • I have the same problem. Still looking... Commented Sep 28, 2018 at 22:15

3 Answers 3

10

The easiest way to accomplish that is to use a module map file. Below I assume you have the Proto.framework in a separate project, which is called Proto.

  1. Create a module.modulemap file in your framework containing the following (substitute the path to the header file as needed):

_

framework module Proto { umbrella header "Proto.h" // Load a C header to be used in Swift - here /usr/include/sys/stat.h: header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/sys/stat.h" export * module * { export * } } 
  1. In your project build settings find Module Map File in section Packaging. Enter $(SRCROOT)/Proto/module.modulemap

That's it. From now on you should be able to use anything declared in stat.h in Swift.

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

3 Comments

not seeing a module map setting in Xcode 7.2 either unfortunately
@MaxMacLeod just create a new file in a text editor (TextWrangler for example) and drag n drop it to your project. Don't forget to select the target.
Did it worked for archiving the app as well?, after adding module.map I could resolve the issue of "include of Non modular headers" , But When I archive the project it does not find the bridging header file. complain for missing header. When I check build folder for release in derived data I dont see any hedaer file there. which was present before adding module map. any idea? I am working on xcode 10
2

In your build settings for Proto.framework try setting the option Allow Non-modular Includes In Framework Modules to Yes.

Xcode Settings

3 Comments

Just gave it a shot and still getting error: include of non-modular header inside framework module Proto :\
I have the same problem (xcode 7, swift 2). Anyone find a solution?
I had to make the additional header public that I was importing inside the umbrella header
0

I resolved this error by making the header Public (instead of Project)

Go to your target Build Phases and move the header accordingly:

Header visibility settings

This works for my 'lib' target. But I am still unable to build libTests target. Here I get 2 errors:

  • 'header.h' file not found with include; use "quotes" instead
  • and again: Include of non-modular header inside framework module 'lib'

this I am not able to resolve yet

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.