C++ -fvisibility=hidden -fvisibility-inlines-hidden C++ -fvisibility=hidden -fvisibility-inlines-hidden linux linux

C++ -fvisibility=hidden -fvisibility-inlines-hidden


-fvisibility=hidden makes all your symbols hidden by default.

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(){    // ...}


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.

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-sections will reduce the shared object size further by having the definition which is relevant to those 100 symbols.