diff --git a/lang/c++/impl/json/JsonDom.hh b/lang/c++/impl/json/JsonDom.hh index 75728c6badd..b2be02b30cd 100644 --- a/lang/c++/impl/json/JsonDom.hh +++ b/lang/c++/impl/json/JsonDom.hh @@ -31,7 +31,7 @@ namespace avro { -class AVRO_DECL InputStream; +class InputStream; namespace json { class Entity; @@ -59,7 +59,7 @@ enum class EntityType { Obj }; -const char *typeToString(EntityType t); +AVRO_DECL const char *typeToString(EntityType t); inline std::ostream &operator<<(std::ostream &os, EntityType et) { return os << typeToString(et); diff --git a/lang/c++/include/avro/Compiler.hh b/lang/c++/include/avro/Compiler.hh index 911a8aed0cd..9c9ec8a71fb 100644 --- a/lang/c++/include/avro/Compiler.hh +++ b/lang/c++/include/avro/Compiler.hh @@ -26,15 +26,15 @@ namespace avro { -class AVRO_DECL InputStream; +class InputStream; /// This class is used to implement an avro spec parser using a flex/bison /// compiler. In order for the lexer to be reentrant, this class provides a /// lexer object for each parse. The bison parser also uses this class to /// build up an avro parse tree as the avro spec is parsed. -class AVRO_DECL Name; -class AVRO_DECL ValidSchema; +class Name; +class ValidSchema; /// Given a stream containing a JSON schema, compiles the schema to a /// ValidSchema object. Throws if the schema cannot be compiled to a valid @@ -60,7 +60,7 @@ AVRO_DECL ValidSchema compileJsonSchemaFromString(const std::string &input); AVRO_DECL ValidSchema compileJsonSchemaFromFile(const char *filename); -AVRO_DECL ValidSchema compileJsonSchemaWithNamedReferences(std::istream &is, +AVRO_DECL ValidSchema compileJsonSchemaWithNamedReferences(std::istream &is, const std::map &namedReferences); } // namespace avro diff --git a/lang/c++/include/avro/Config.hh b/lang/c++/include/avro/Config.hh index dd2438debbe..3c213543d79 100644 --- a/lang/c++/include/avro/Config.hh +++ b/lang/c++/include/avro/Config.hh @@ -19,25 +19,45 @@ #ifndef avro_Config_hh #define avro_Config_hh -// Windows DLL support - -#ifdef _WIN32 +#ifdef _MSC_VER #pragma warning(disable : 4275 4251) +#endif // _MSC_VER + +/* + * Symbol visibility macros: + * - AVRO_DLL_EXPORT annotation for exporting symbols + * - AVRO_DLL_IMPORT annotation for importing symbols + * - AVRO_DLL_HIDDEN annotation for hiding symbols + * - AVRO_DYN_LINK needs to be defined when compiling / linking avro as dynamic library + * - AVRO_SOURCE needs to be defined when compiling avro as library + * - AVRO_DECL contains the correct symbol visibility annotation depending on the two macros above + */ + +#if defined _WIN32 || defined __CYGWIN__ +#define AVRO_DLL_EXPORT __declspec(dllexport) +#define AVRO_DLL_IMPORT __declspec(dllimport) +#define AVRO_DLL_HIDDEN +#else +#define AVRO_DLL_EXPORT [[gnu::visibility("default")]] +#define AVRO_DLL_IMPORT [[gnu::visibility("default")]] +#define AVRO_DLL_HIDDEN [[gnu::visibility("hidden")]] +#endif // _WIN32 || __CYGWIN__ -#if defined(AVRO_DYN_LINK) +#ifdef AVRO_DYN_LINK #ifdef AVRO_SOURCE -#define AVRO_DECL __declspec(dllexport) +#define AVRO_DECL AVRO_DLL_EXPORT #else -#define AVRO_DECL __declspec(dllimport) +#define AVRO_DECL AVRO_DLL_IMPORT #endif // AVRO_SOURCE #endif // AVRO_DYN_LINK -#include -using ssize_t = SSIZE_T; -#endif // _WIN32 - #ifndef AVRO_DECL #define AVRO_DECL #endif +#ifdef _WIN32 +#include +using ssize_t = SSIZE_T; +#endif // _WIN32 + #endif diff --git a/lang/c++/include/avro/buffer/BufferStream.hh b/lang/c++/include/avro/buffer/BufferStream.hh index a8510adaa1c..3aeda37f0f7 100644 --- a/lang/c++/include/avro/buffer/BufferStream.hh +++ b/lang/c++/include/avro/buffer/BufferStream.hh @@ -35,7 +35,7 @@ namespace avro { * **/ -class AVRO_DECL ostream : public std::ostream { +class ostream : public std::ostream { public: /// Default constructor, creates a new OutputBuffer. @@ -65,7 +65,7 @@ protected: * **/ -class AVRO_DECL istream : public std::istream { +class istream : public std::istream { public: /// Constructor, requires an InputBuffer to read from. diff --git a/lang/c++/include/avro/buffer/BufferStreambuf.hh b/lang/c++/include/avro/buffer/BufferStreambuf.hh index 42eb20c21c6..38cc91fce62 100644 --- a/lang/c++/include/avro/buffer/BufferStreambuf.hh +++ b/lang/c++/include/avro/buffer/BufferStreambuf.hh @@ -41,7 +41,7 @@ namespace avro { * but we have no need since all writes are immediately stored in the buffer. **/ -class AVRO_DECL ostreambuf : public std::streambuf { +class ostreambuf : public std::streambuf { public: /// Default constructor creates a new OutputBuffer. @@ -86,7 +86,7 @@ private: * **/ -class AVRO_DECL istreambuf : public std::streambuf { +class istreambuf : public std::streambuf { public: /// Default constructor requires an InputBuffer to read from.