Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is _GLIBCXX_VISIBILITY?

Tags:

c++

g++

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)?

like image 869
user3875690 Avatar asked Mar 26 '15 02:03

user3875690


1 Answers

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

like image 183
David Saxon Avatar answered Nov 14 '22 12:11

David Saxon