A neat way of exporting DLL symbols?
I know that in MSVC we can export all symbols from a C++ class by using a suitable export specifier applied to the whole class. Or alternatively we can export certain functions selectively by preceding each declaration individually with __declspec(dllexport). But apparently the gcc processor has a neat little pragma for doing this - e.g.
#define MY_EXPORT_SPECIFIER __attribute__ ((visibility ("default")))
class MY_EXPORT_SPECIFIER MyClass
// c'tor and d'tor get exported due to MY_EXPORT_SPECIFIER
// Private data and functions are not exported
#pragma GCC visibility push(hidden)
// Declare private data and functions
// Publicly declared functions are now exported again
Okay, it might seem a bit lazy but I think that's quite neat - much better than the MSVC way of needing to address each function individually. Or is it? Is there any similar little trick we can do in MSVC?
"A problem well stated is a problem half solved.” - Charles F. Kettering