框架的专用模块映射 [英] Private module map for a framework
问题描述
我正在使用此答案来创建模块映射,以创建用于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并将其导入到项目中会导致Redefinition of module '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在Framework中的internal
访问属性).
llvm Clang文档显示 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)
在构建阶段被换出到正确的位置(对于iphoneos
或iphonesimulator
SDK):
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
尝试过此操作,但它适用于libz
Disclaimer: I have not tried this for CommonCrypto
but it works for my case with libz
对此的一种可能的解决方案是按照 C文件
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屋!