iOS: "Include of non-modular header" 与 libxml

iOS: "Include of non-modular header" with libxml

我正在尝试构建自己的框架 'VBL',它使用基于 libxml.dylib

TouchXML

框架构建良好,但每当我尝试在任何项目中使用它时,我都会收到以下错误:

"Include of non-modular header inside framework module VBL.CXMLNode"

那是因为在我的框架内的 header CXMLNode.h 中,我必须按如下方式包含 libxml:

#include <libxml/tree.h>

在 Build Settings 中将以下 属性 设置为 YES 是否安全?

allow non-modular included in framework modules

但这无论如何都不适用于 Swift,还有其他建议吗?

如果可以,您可以尝试将 #include <libxml/tree.h> 隐藏在私有 header 或 .m 文件中。

您也可以尝试创建一个 module.modulemap 文件,其中包含 libxml 根目录 header 以欺骗 swift 编译器:

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

然后将文件放在一个文件夹中,-module/module.modulemap- 例如。

一旦你这样做了,你应该 link 它在目标 build settingswift compiler search path 部分内的 import paths 和目标的 header search path

$(SRCROOT)/module

然后在你的代码中,你可以使用@import libxml;