I am trying to perform any of the following in C++:
if( compiler_setting.find( "-fvisibility=hidden" ) )
{
printf( "Default visibility is hidden\n" );
}
if( compiler_setting.find( "-fvisibility-inlines-hidden" ) )
{
printf( "Default visibility for inline is hidden\n" );
}
if( visibility_of( myFunction ) == "__attribute__( ( visibility( \"hidden\" ) ) )" )
{
printf( "Visibility of myFunction is hidden\n" );
}
But I can't find any way to retrieving even a glimpse of information about this.
Obviously this can't be standard C++ since these annotations are attributes outside of the spec; thus usage of any compiler extension to retrieve this information is ok.
The use case scenario is that I am strengthening ABI compatibility between libraries and apps and detect/troubleshoot these problems at runtime rather than have a random failure deep in the codebase after having run for minutes (true story...).
Update:
The answers I've had so far are valid, thanks!
The thing is, I'm a C++ library writer and thus I don't have control of the application that's going to be using it. I want to be as less intrusive as possible from the app side.
I can indeed use build script magic to embed the params used for building the library into a header file; but I cannot do the same for the application (well I could, but I would be forcing a build system on them).
The current version is already handling common user errors (like mixing old libs with new ones, using a lib. with incompatible CMake options, mixing Debug with Release).
I am very happy with the current version, but I wanted to account for visibility=hidden specifically because it can cause deeply hidden bugs (those that trigger very rarely and make your eyes wide open on what the code is doing because it makes no sense).
If it's possible to check the attributes of a function instead of compiler flags, that'd be also fine by me, e.g. something like:
class MyTestClass {};
if( attributes( MyTestClass ).hidden )
{
printf( "Default visibility is hidden\n" );
}