带有 libxml 的 Swift 框架 [英] Swift Framework with libxml

查看:11
本文介绍了带有 libxml 的 Swift 框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 KissXML Objective-C 库的 Swift 框架项目.KissXML 在内部使用 libxml.

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

当我构建 xcode 项目(Xcode 6 - beta 5)时,我收到此错误:

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

error: <unknown>:0: error: '/SwiftFramework/SwiftFramework/KissXML/DDXMLNode.h:2: 在框架模块 SwiftFramework.DDXMLNode 中包含非模块化标头

我看过这个 answer 讨论公开相关的头文件.我已经这样做了,但我不确定如何解决在 DDXMLNode.h 中导入的此标头的情况,这不是我项目的明确部分:

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?

注意:我在一个仅限 Objective-C 的项目中使用了 KissXML,它运行良好(Xcode 5).

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

推荐答案

诀窍是创建一个模块并将其包含在您的项目中.

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

要创建模块,您需要创建一个名为 module.modulemap 的文件,该文件将 API 导出到感兴趣的头文件中,如下所示:

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 *
}

请注意,您需要为模拟器和实际设备执行此操作 - 因此文件中有 2 个条目.

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

这个文件module.modulemap可以放在任何地方.我在 Xcode 的项目文件 (.xcodeproj) 的同一级别创建了一个名为 modules 的目录,并将 module.modulemap 文件放在那里.

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.

然后将包含此文件的目录添加到 Xcode 项目的 Build Settings 下的 Header Search Path.

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

在此示例中,您只需将单词 modules 添加到 Header Search Path,因为 modules 目录位于与 Xcode 项目文件相同的级别.这将在内部更新 Xcode 项目变量 HEADER_SEARCH_PATHS.就是这样.

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.

这篇关于带有 libxml 的 Swift 框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆