Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift Framework with libxml

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).

like image 444
infinite-loop Avatar asked Aug 06 '14 23:08

infinite-loop


2 Answers

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.

like image 198
infinite-loop Avatar answered Nov 12 '22 18:11

infinite-loop


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

like image 24
javaing Avatar answered Nov 12 '22 18:11

javaing