如何在Swift中使用libxml? [英] How to use libxml in Swift?

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

问题描述

我尝试使用这种新语言用我的一些旧代码启动一个新项目,
我在我的旧项目中使用了Libxml2.2,因此xcode显示找不到libxml.h / parse.h文件在我将代码放入我的新项目之后。
i已经导入了libxml2.2.dylib

I try to use this new language to start a new project with Some of my old code, I used Libxml2.2 in my old project,so xcode shows "libxml.h/parse.h file not found" after my putting the code in my new project. i have already imported the "libxml2.2.dylib"

推荐答案

我已经使用了CommonCrypto https://github.com/onmyway133/CommonCrypto.swift 但libxml应该是相同的。需要注意的事项

I 've made it work with CommonCrypto https://github.com/onmyway133/CommonCrypto.swift but libxml should be the same. Things to keep in mind

module.modulemap

阅读 http://clang.llvm.org/docs/Modules.html#module-map-语言

创建一个名为 libxml2 的文件夹(在我的例子中,它与我的项目文件),然后在里面创建一个 module.modulemap 文件

Create a folder named libxml2 (in my case, it is at the same directory as my project file), then create a module.modulemap file inside

module libxml2 {
  header "/usr/include/libxml2/libxml/tree.h"
  export *
}

这里我只添加 tree.h ,但您可以根据需要添加更多

Here I add just tree.h, but you can add more for your need

SWIFT_INCLUDE_PATHS

转到目标构建设置,将其添加到导入路径

Go to Target Build Settings, add this into Import Paths

${SRCROOT}/libxml2

HEADER_SEARCH_PATHS

阅读为什么我得到这个未找到libxml / tree.h文件错误?

转到目标构建设置,将其添加到标题搜索路径

Go to Target Build Settings, add this into Header Search Paths

$(SDKROOT)/usr/include/libxml2

有趣的相关帖子

  • Swift Framework with libxml
  • https://spin.atomicobject.com/2015/02/23/c-libraries-swift/
  • Importing CommonCrypto in a Swift framework
  • https://github.com/onmyway133/Reindeer

这篇关于如何在Swift中使用libxml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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