7

I have Swift Framework project that uses the KissXML Objective-C library. KissXML internally uses libxml.

When I build the xcode project (Xcode 6 - beta 5), I get this error:

error: <unknown>:0: error: '/SwiftFramework/SwiftFramework/KissXML/DDXMLNode.h:2: include of non-modular header inside framework module SwiftFramework.DDXMLNode

I have seen this answer that discusses making the relevant header files public. I have done that but I am not sure how to address the case of this header that is imported in the DDXMLNode.h and that is not explicitly part of my project:

#import <libxml/tree.h>

Any suggestions on how to handle this?

Note: I have used KissXML on a Objective-C only project and it worked fine (Xcode 5).

Community
  • 1
  • 1
infinite-loop
  • 882
  • 11
  • 17

2 Answers2

10

The trick is to create a module and include it on your project.

To create the module you create a file named, let's say, module.modulemap which exports the API on the header files of interest like this:

module libxmlModuleDevice {
    header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/libxml2/libxml/tree.h"
    export *
}

module libxmlModuleSimulator {
    header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/libxml2/libxml/tree.h"
    export *
}

Notice that you need to do this both for the simulator and for the actual device - hence the 2 entries on the file.

This file module.modulemap can be placed anywhere. I created a directory called modules at the same level as the Xcode's project file (.xcodeproj) and placed the module.modulemap file there.

Then add directory that contains this file to the Header Search Path under Build Settings of you Xcode project.

In this example all you have to do is to add the word modules to the Header Search Path because the modules directory is at the same level as the Xcode project file. This will update internally the Xcode project variable HEADER_SEARCH_PATHS. That's it.

infinite-loop
  • 882
  • 11
  • 17
  • I tried your solution but I can manage to make it work, could you detail more the process ? – Loegic Jul 28 '15 at 09:44
  • 1
    I added more details try it out and let me know how it goes. Cheers. – infinite-loop Jul 29 '15 at 01:33
  • Thanks @infinite-loop, I did what you said, and Xcode is able to find the new module, however, at the compile phase, it will throw an error "libXmlModuleDevice" (or whatever) not found :/ – Loegic Jul 29 '15 at 10:30
  • Hhhhmmmm... Can you 2x check that the 2 paths exist on your the file system? If not please adjust them them to point to the correct paths. – infinite-loop Jul 29 '15 at 16:37
  • I did it (I upvoted the answer), my project contains two target, I have to add it to both build settings. Thanks :] – Loegic Jul 30 '15 at 09:14
2

in xcode6, iphone8.3, the path will be

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.3.sdk/usr/include/libxml2

*update: a more easy way: $(SDKROOT)/usr/include/libxml2
thank to: iPhone libxml2 not found during build

Community
  • 1
  • 1
javaing
  • 33
  • 6