问题
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