29

Here’s my setup:

  1. Static library of Objective C code called Stat.
  2. A Swift framework that uses code from Stat in its own classes (this framework is called Dyn). The static library and this framework are in the same Xcode project.
  3. A Mac app / project that has the above project as a subproject and which links to Dyn.

In my app I have code like:

import Cocoa
import Dyn
...
SomeDynClass().doSomething()

However, when I try to compile I get an error when I import Dyn. The error is

error: missing required module ‘Stat'

It appears my app can find my framework just fine, but it somehow needs to find a module for my static library, too?

Stat has a module file that’s pretty basic:

module Stat {
    header "Stat.h"
    export *
}

I think I need to point my Mac app’s framework search paths at Stat but I don’t know why and I don’t know how. How do I solve this?

jbrennan
  • 11,943
  • 14
  • 73
  • 115
  • I know its more than a year old, but did you find a solution? I have similar problem now with OpenSSL. I built my own .a files libcrypto and libssl and created module.modulemap for them (module name: COpenSSL). I can use this in my swift framework (also the tests are working) but when I use this framework in an application I get: Missing required module: COpenSSL – leizeQ Oct 20 '16 at 13:51
  • @leizeQ Have you tried linking to `COpenSSL` in your application too? I'm not sure if that'll work, but it's worth a shot! – jbrennan Oct 22 '16 at 14:48
  • @jbrennan In my case both Stat and Dyn are swift. Stat i assume i can now build using XCODE 9.1 (it support swift static lib). Question is where to include module map for stat and what should be in modulemap file? – harshit2811 Nov 17 '17 at 06:48

2 Answers2

27

Select your Target, then go into Build Settings and set the Import Paths within the Swift Compiler - Search Paths section:

${SRCROOT}/Stat

Normally the module would be named the same as the library, however, I'm not sure how you've setup the directory with the module.map (it could be named Dyn perhaps, in which case the Import Path would reflect that name.

Build Settings > Swift Compiler > Search Paths:

enter image description here

${SRCROOT}/(directory with module.map) should resolve itself once you press enter or tab..

Community
  • 1
  • 1
l'L'l
  • 44,951
  • 10
  • 95
  • 146
  • Ah shoot! So I had tried this (after your suggestion) and it didn’t work. But What I needed to do was add this in my APP target (the app that links to Dyn, which imports Stat). It’s hard to remember if I had changed other settings last week, but I believe that’s what I needed to do. Thank you. – jbrennan Aug 10 '15 at 21:15
  • Drat, I take that back. I was in the wrong project. What seems to be an issue is my Dyn framework and Stat library are in nested projects. So, App has them as subprojects, and this seems to cause things to not build, even with the import paths you suggest in the App target. – jbrennan Aug 10 '15 at 21:23
  • @jbrennan: In your framework build settings do you have the swift compiler search paths defined, and if you build the framework by itself does everything compile properly? – l'L'l Aug 11 '15 at 07:09
  • 5
    This resolved a similar issue for me, where I had a Swift app target (App) importing a dynamic framework (Core) which was linking a number of static frameworks united by an umbrella module map (Firebase). This produced "Missing required module: Firebase" errors, in the App target, when it imported Core. The errors went away when I updated the Core build settings to add the module map's directory to the Swift Compiler Paths - Import Paths. – algal Mar 20 '19 at 20:36
  • 5
    Same for me. I have `@_exported import MyLib` that has Firebase dependency. Specifying `${SRCROOT}/Pods/Firebase/CoreOnly/Sources` for Import Paths fixed "Error: missing required module 'Firebase'" – Leo Aug 26 '19 at 20:13
  • my problem is `missing required module 'CTweetNacl'`, but I don't use this framework at all. Do you have any ideas? – Taras Nov 25 '21 at 12:48
2

I got the same error when in my unit tests project which involves SQLite3 package. After I add the package, unit tests always throw out error saying "missing required module SQLiteObjc"

I had it fixed by toggle "Force Package Info Generation" on and off in my Unit Tests Target's build setting

Tomasen
  • 142
  • 1
  • 3