不要在自己的静态库使用的库符号曝光 [英] Don't expose symbols from a used library in own static library
问题描述
我写的iPhone可重复使用的静态库,提供的路线<跟随href=\"http://www.amateurinmotion.com/articles/2009/02/08/creating-a-static-library-for-iphone.html\">here.
I am writing a reusable static library for the iPhone, following the directions provided here.
我想用 minizip
在我的图书馆内,但不希望将其暴露给用户。
I want to use minizip
in my library internally, but don't want to expose it to the user.
应该可以为用户包括minizip自己,可能是不同的版本,并没有引起我的内部minizip版本冲突。
It should be possible for the user to include minizip themselves, possibly a different version, and not cause clashes with my "inner" minizip version.
这可能吗?
编辑:
我试着加入 = -fvisibility隐藏
额外的编译器标志minizip文件和转变职能为 __ private_extern__
和 __ __属性((能见度(隐藏)))
,但它仍然似乎产生定义的外部符号:
I've tried adding -fvisibility=hidden
to additional compiler flags for minizip files and changing functions to be __private_extern__
and __attribute__((visibility("hidden")))
, but it still seems to produce defined external symbols:
00000918 T _unzOpen
0000058e T _unzOpen2
00001d06 T _unzOpenCurrentFile
00001d6b T _unzOpenCurrentFile2
...
编辑#2:
显然,标有这些注释符号链接器,当X code构建的来源,因为它增加了-c参数(编译或汇编源文件,这从未发生过只为私有,但不要链接。)
Apparently the symbols marked with these annotations are only made private by the linker, which never happens when Xcode builds the sources, since it adds the -c parameter ("Compile or assemble the source files, but do not link.")
推荐答案
您可以用objcopy把重命名 minizip
全部出口标志。
You could rename all exported symbol from minizip
with objcopy.
像
objcopy -redefine-sym=minizip.syms yourstaticlibray.a
和 minizip.syms
_unzOpen _yourownprefix_unzOpen
_unzOpen2 _yourownprefix_unzOpen2
... ...
没有如果可执行文件相链接的交锋其他 minizip.a
和 yourstaticlibray.a
,因为你改名为所有的符号 yourstaticlibray.a
内部呼叫 yourstaticlibray.a
到 minizip
将使用prefixed符号,而不是unzOpen之一。
No clash if an executable is linked with an other minizip.a
and yourstaticlibray.a
, and because you renamed all the symbol in yourstaticlibray.a
your call inside yourstaticlibray.a
to minizip
will use the prefixed symbol, and not the unzOpen one.
这篇关于不要在自己的静态库使用的库符号曝光的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!