As ugly as win32 Microsoft compiler is by using the __declspec macro, it does have the advantage of being explicit about what you want to export or not.
Moving the same code onto a Linux gnu/gcc system now means all classes are exported!(?)
Is this really true?
Is there a way to NOT export a class within a shared library under gcc?
#ifndef WIN32
#define __IMPEXP__
#else
#undef __IMPEXP__
#ifdef __BUILDING_PULSETRACKER__
#define __IMPEXP__ __declspec(dllexport)
#else
#define __IMPEXP__ __declspec(dllimport)
#endif // __BUILDING_PULSETRACKER__
#endif // _WIN32
class __IMPEXP__ MyClass
{
...
}
This is possible in GCC 4.0 and later. The GCC folks consider this visibility. There is a good article on the GCC wiki about the subject. Here is a snippet from that article:
If a class shouldn't be available, it shouldn't be in a public header. What is the point of sharing declarations of things the user can't use?