What is _GLIBCXX_VISIBILITY?

跟風遠走 提交于 2020-12-25 03:51:16

问题


I was going through the source of some of the standard headers included with gcc (in /usr/include/c++/ ) and found the following at the top of every header:

namespace std _GLIBCXX_VISIBILITY(default)

What exactly is _GLIBCXX_VISIBILITY(default)?


回答1:


It's a preprocessor macro. And is defined as:

#if _GLIBCXX_HAVE_ATTRIBUTE_VISIBILITY
#define _GLIBCXX_VISIBILITY(V) __attribute__ ((__visibility__ (#V)))
#else
#define _GLIBCXX_VISIBILITY(V) 
#endif

So if _GLIBCXX_HAVE_ATTRIBUTE_VISIBILITY is true then in your case it will expand to:

__attribute__ (( __visibility__ ("default")))

else if _GLIBCXX_HAVE_ATTRIBUTE_VISIBILITY is false it will do nothing.

The __visibility__ attribute is used for defining the visibility of the symbols in a DSO file. Using "hidden" instead of "default" can be used to hide symbols from things outside the DSO.

For example:

__attribute__ ((__visibility__("default"))) void foo();
__attribute__ ((__visibility__("hidden"))) void bar();

The function foo() would be useable from outside the DSO whereas bar() is basically private and can only be used inside the DSO.

You can read a bit more about the __visibility__ attribute here: https://gcc.gnu.org/wiki/Visibility



来源:https://stackoverflow.com/questions/29270208/what-is-glibcxx-visibility

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!