The following is a common pattern in cross-platform libraries that are compiled as shared libraries with default visibility hidden
:
#if defined _WIN32
#ifdef BUILDING_DLL
#define DLL_PUBLIC __declspec(dllexport)
#else
#define DLL_PUBLIC __declspec(dllimport)
#endif
#else
#define DLL_PUBLIC __attribute__ ((visibility ("default")))
#endif
How is it that on Visual Studio we need two different keywords when compiling and when using the shared library, while with the GNU compiler we get away with only one?
Theories:
- Are the methods not as equivalent as they seem and therefore are there pitfalls to watch out for?
- Is the two keyword method on Visual Studio there only for historic reasons?
- Are there some internal technical differences that make the keyword necessary with Visual Studio (for example the way information is passed to the linker)?