框架的私有模块映射 [英] Private module map for a framework

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

问题描述

我正在使用 this answer 创建一个模块映射来为 CommonCrypto 创建一个模块,这样我就可以在一个框架.

I'm using this answer to create a module map to create a module for CommonCrypto so I can use it in a framework.

但是,这样做意味着我使用此框架的任何项目都可以通过 import CommonCrypto 访问 CommonCrypto - 更糟糕的是,在另一个框架中声明 CommonCrypto 并将其导入项目会导致 重新定义模块CommonCrypto" 错误.

Doing this however means that any projects that I use this framework in have access to CommonCrypto with import CommonCrypto - and even worse, declaring CommonCrypto in another framework and importing this into the project results in Redefinition of module 'CommonCrypto' errors.

即以下设置:

MainProject
    |--> import FrameworkA - module map for CommonCrypto
    |--> import FrameworkB - module map for CommonCrypto

有没有办法创建一个模块映射,但让它私有于它创建/使用的框架?(很像框架的 Swift 中的 internal 访问属性).llvm Clang 文档 显示了一个 private 属性 但我不知道在我的模块映射中放置这个,甚至可能不是为了这个目的!还有一个 export 属性 但我又一次'不完全确定如何使用它...!

Is there a way to create a module map but have it private to that Framework its created/used in? (Much like the internal access attribute in Swift for a Framework). The llvm Clang docs show a private attribute but I can't work out where to put this in my module map, and it might not even be for this purpose! There's also an export attribute but again I'm not entirely sure how to use this...!

这是我用于 CommonCrypto 的模块映射 - $(SDKROOT) 在构建阶段被换出到正确的位置(对于 iphoneosiphonesimulator SDKs):

This is my module map I'm using for CommonCrypto - the $(SDKROOT) gets swapped out in a build phase to the correct location (for iphoneos or iphonesimulator SDKs):

module CommonCrypto [system] [extern_c] {
    umbrella header "$(SDKROOT)/usr/include/CommonCrypto/CommonCrypto.h"
    export *
}

FrameworkA/FrameworkB 中使用这很好(除了你不能去定义",但我不介意).

This works fine (except you can't "go to definition" but I don't mind that) for use in FrameworkA / FrameworkB.

推荐答案

免责声明:我没有为 CommonCrypto 尝试过这个,但它适用于我的情况

Disclaimer: I have not tried this for CommonCrypto but it works for my case with libz

一个可能的解决方案是创建一个 module.private.modulemap,如 Clang 文档

A possible solution to this is to create a module.private.modulemap as described in the Clang documentation

因此,例如在 FrameworkA 中,您可以为 FrameworkA 编写一个 module.modulemap 文件,如下所示:

So for example in FrameworkA you can write a module.modulemap file for FrameworkA like so:

module FrameworkACommon {
}

然后你会像这样创建一个 module.private.modulemap 文件

Then you would create a module.private.modulemap file like so

explicit  FrameworkACommon.Crypto [system] [extern_c] {
   header "/Applications/Xcode6-Beta5.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.0.sdk/usr/include/CommonCrypto/CommonCrypto.h"
    link "CommonCrypto"
    export *
}

然后对 FrameworkB 重复.

现在 CommonCrypto 是 FrameworkA 和 FrameworkB 中的私有模块,名称不会冲突.

Now CommonCrypto is a private module in both FrameworkA and FrameworkB and the names won't clash.

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

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