xcode 框架的私有模块映射

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34265339/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 08:18:55  来源:igfitidea点击:

Private module map for a framework

xcodeswiftframeworksdylibllvm-clang

提问by Rich

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

我正在使用这个答案来创建一个模块映射来为 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.

然而,这样做意味着我使用这个框架的任何项目都可以访问 CommonCrypto,import CommonCrypto更糟糕的是,在另一个框架中声明 CommonCrypto 并将其导入到项目中会导致Redefinition of module 'CommonCrypto'错误。

I.e. the following setup:

即以下设置:

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

Is there a way to create a module map but have it private to that Framework its created/used in? (Much like the internalaccess attribute in Swift for a Framework). The llvm Clang docsshow a privateattributebut 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 exportattributebut again I'm not entirely sure how to use this...!

有没有办法创建一个模块映射,但让它私有于它创建/使用的那个框架?(很像internalSwift for a Framework 中的access 属性)。该LLVM锵文档显示private属性,但我不能工作在什么地方把这个在我的模块图,它甚至可能不是为了这个目的!还有一个export属性,但我又不完全确定如何使用它......!

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

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

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

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

这工作正常(除非您不能“转到定义”,但我不介意)用于FrameworkA/ FrameworkB

回答by tmpz

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

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

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

一个可能的解决方案是创建一个module.private.modulemapClang 文档中描述的

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

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

module FrameworkACommon {
}

Then you would create a module.private.modulemapfile like so

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

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

Then repeat for FrameworkB.

然后对 FrameworkB 重复。

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

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