C++ -fvisibility=hidden -fvisibility-inlines-hidden
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3570355/
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
C++ -fvisibility=hidden -fvisibility-inlines-hidden
提问by nixgadget
I have a question about the C++ visibility attribute. I have read http://gcc.gnu.org/wiki/Visibilityand yet I dont quite understand how it works.
我有一个关于 C++ 可见性属性的问题。我已经阅读了http://gcc.gnu.org/wiki/Visibility,但我不太明白它是如何工作的。
I want use the visibility to be hidden on some of my shared libraries I have. I believe this means that the symbols are hidden ?
我想使用可见性隐藏在我拥有的一些共享库中。我相信这意味着符号被隐藏了?
How are you meant to link the shared library then ? Is there a special way ? If I link it how it normally gets linked it doesnt work.
那么你打算如何链接共享库?有什么特别的方法吗?如果我链接它通常如何链接它不起作用。
Can someone help me please.
有人能帮助我吗。
回答by CB Bailey
-fvisibility=hidden
makes all your symbols hidden by default.
-fvisibility=hidden
默认情况下隐藏所有符号。
What you then have to do, is choose which functions you want to be visible to users linking against your library and make them visible by marking them with a visible attribute.
然后您要做的是选择您希望对链接到您的库的用户可见的功能,并通过将它们标记为可见属性来使它们可见。
E.g.
例如
void __attribute__((visibility("default"))) Exported()
{
// ...
}
回答by Arunprasad Rajkumar
It reduces the keeping unnecessary symbol information that is private to Shared Objects.
它减少了保留共享对象私有的不必要的符号信息。
Consider a shared object which has more than 10,000 symbols (functions/global variables), but only 100 of them were public functions accessible from library users. We can make the only 100 functions as visible to others & remaining 9,900 symbols as private.
考虑一个共享对象,它有 10,000 多个符号(函数/全局变量),但其中只有 100 个是库用户可访问的公共函数。我们可以将仅有的 100 个函数设为对其他人可见,其余 9,900 个符号设为私有。
It will reduce shared object's size as well, because its relocation table will have only 100 symbols of information. Using this flag along with -ffunction-sections -fdata-sectionswill reduce the shared object size further by having the definition which is relevant to those 100 symbols.
它也会减少共享对象的大小,因为它的重定位表将只有 100 个信息符号。将此标志与-ffunction-sections -fdata-sections一起使用将通过具有与这 100 个符号相关的定义进一步减小共享对象的大小。