5

I have looked at answers to similar problems and I'm still confused.

Background

I had a project working, but I'm trying to recreate it in Xcode 8.3.1. I start by using the Swift Package Manager with one dependency: [.Package(url: "https://github.com/OpenKitten/MongoKitten.git", majorVersion: 3)]. I then follow my notes to convert from Cocoa to iOS (because SPM doesn't directly support iOS) that worked in previous project starts:

  1. Make starting Package.swift file
  2. swift package generate-xcodeproj
  3. Open project in Xcode
  4. Project : Build Settings : Base SDK ==> change to IOS
  5. Editor : Add Target : (iOS ... Single View App)
  6. Select your project, look at target list, find your newly added target : General : Deployment Info
  7. On toolbar, change "active scheme"

Everything seems fine, and my project includes MongoKitten and a bunch of other frameworks that it relies on. One of which is called "CLibreSSL". I added all of the frameworks as targets to my newly created target.

Error Message

I can "Import MongoKitten" into my viewcontroller (with autocomplete working). However, when I compile, I get this error message (even though I personally did not try to Import CLibreSSL):

Compile Swift source files 
[... bunch of stuff referring to my new target and the viewcontroller ...] 
<unknown>:0: error: missing required module 'CLibreSSL' 

I cannot "Import CLibreSSL" into my viewcontroller (no autocomplete recognition). I notice that when I go to the MongoKitten-related source files, they do recognize CLibreSSL successfully in their import statements. I can even delete them and retype with successful autocompletion.

Question

I realize I probably need to do something additional when I make a new target like I did, and it probably has something to do with the search paths, but I've tried a lot of stuff and the result has not changed. Can someone please tell me how to resolve this (and please don't assume too much knowledge on my part as I find this stuff confusing)?

Please let me know if you need more information. Thank you

Narwhal
  • 744
  • 1
  • 8
  • 22

2 Answers2

3

i had the same issue "missing required module 'CLibreSSL'" when including Vapor in an iOS App. The fix is pretty simple and should work for you as well:

Go to your project’s Build Settings. Find the header Swift Compiler — Search Paths. In Import Paths, add a relative path to your C library’s folder using ${SRCROOT}. If your folder includes subfolders select the recursive option.

It's a tip from here

EDIT May 26,2017: As suggested in the comments - My solution does not work for me as well, when using real device. I was only playing around in simulator, where this fix helped. So sorry for the confusion. When compiling for real device, CLibreSSL/getentropy_osx.c does not compile due to missing header files (e.g. <sys/vmmeter.h>) - So bottomline: My suggestion works for me only in simulator. :-/

O. Nauroth
  • 61
  • 4
  • Thank you. I will keep this answer in mind, but in this particular case it did not solve it. – Narwhal Apr 22 '17 at 20:47
  • This didn't work for me either... Narwhal, did you find a solution? – jbm May 08 '17 at 18:08
  • 2
    setting header search path in search path section is the right way. if the framework depends on some other c framework (defined as external dependecy) the c framework is in a separate module. in that case, the compiler must be instructed how to compile it. check -fmodule-map-files= parameter of c compiler. use -Xcc parameter of swiftc to pass it to c compiler. find module.modulemap in dependency framework and use it as the value. an example "-Xcc -fmodule-map-file=$(SRCROOT)/ClibWrapperTest.xcodeproj/GeneratedModuleMap/Clib/module.modulemap" – user3441734 Jul 29 '17 at 01:07
  • Hi @user3441734, but how to set "-Xcc -fmodule-map-file" in Xcode, could you please give more information? thanks – DàChún Oct 10 '17 at 17:56
  • 2
    @User9527 Build Settings -> Other Swift Flags – user3441734 Oct 10 '17 at 20:52
  • @user3441734, thank you. I don't think that will work for me because the modulemap file and OC Header files are not public. They are invisible outside of the framework – DàChún Oct 11 '17 at 06:07
  • @User9527 most likely you only missed something, please check the clang documentation how modulmap works. https://clang.llvm.org/docs/Modules.html – user3441734 Oct 11 '17 at 18:22
1

Adding the "Other Swift Flags" build setting as suggested by user3441734 fixed it for me. It seems odd that the library (in my case OpenCloudKit) that depends on the CLibreSSL module can find it, but my app that imported OpenCloudKit can't without help. For reference , mine was nested in a SPM-generated Xcode project (named "Dependencies") imported into my app and the build setting was -Xcc -fmodule-map-file=$(SRCROOT)/Dependencies/.build/x86_64-apple-macosx10.10/debug/CLibreSSL.build/module.modulemap. Note that this seems a bit fragile because it has a macOS version hard-coded into the file name and I assume that could break if it's updated to a later version. Also note that the Search Paths build setting was NOT needed in my case, only the Other Swift Paths setting.

Ben Stahl
  • 1,139
  • 11
  • 11
  • 1
    for future reference this also fixed things for me using a SPM project that wraps a C library. I have been following the suggested route for embedding a SPM project into an Xcode MacOS project as referenced in the forums [here](https://forums.swift.org/t/xcode-project-with-spm-dependencies/18157/10) – lbdl Jan 07 '19 at 19:57