Swift Framework with libxml

谁说我不能喝 提交于 2019-12-18 16:30:38

问题


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


回答1:


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.




回答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



来源:https://stackoverflow.com/questions/25171680/swift-framework-with-libxml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!