From fddcb230026cd77e2ea31be0d216aaffbd3ca71a Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Thu, 20 Oct 2022 12:08:03 +0800 Subject: [PATCH] exceptions/exception.h: Try fixing linking on MinGW Using the xmlpp::exception class may lead to a linker error on its vtable on MinGW, unless the whole class is exported, but we also want to avoid exporting that whole class under Visual Studio, so that we can avoid having the built DLL/import library being tied to a particular STL version, so define macros to accomdate such situations and apply it to the xmlpp::exception class. This should not affect the ABI stability on Visual Studio builds. Fixes: https://github.com/libxmlplusplus/libxmlplusplus/issues/45 --- libxml++/exceptions/exception.h | 12 ++++++------ libxml++config.h.in | 11 +++++++++++ libxml++config.h.meson | 11 +++++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/libxml++/exceptions/exception.h b/libxml++/exceptions/exception.h index e6b3d97a..7a657222 100644 --- a/libxml++/exceptions/exception.h +++ b/libxml++/exceptions/exception.h @@ -36,17 +36,17 @@ namespace xmlpp /** Base class for all xmlpp exceptions. */ -class exception : public std::exception +class LIBXMLPP_VISIBILITY_DEFAULT exception : public std::exception { public: - LIBXMLPP_API + LIBXMLPP_MEMBER_METHOD explicit exception(const ustring& message); - LIBXMLPP_API ~exception() noexcept override; + LIBXMLPP_MEMBER_METHOD ~exception() noexcept override; - LIBXMLPP_API const char* what() const noexcept override; + LIBXMLPP_MEMBER_METHOD const char* what() const noexcept override; - LIBXMLPP_API virtual void raise() const; - LIBXMLPP_API virtual exception* clone() const; + LIBXMLPP_MEMBER_METHOD virtual void raise() const; + LIBXMLPP_MEMBER_METHOD virtual exception* clone() const; private: ustring message_; diff --git a/libxml++config.h.in b/libxml++config.h.in index cfa46e4d..4310c295 100755 --- a/libxml++config.h.in +++ b/libxml++config.h.in @@ -24,6 +24,10 @@ #ifdef LIBXMLPP_DLL #ifdef LIBXMLPP_BUILD #define LIBXMLPP_API __declspec(dllexport) + #ifdef __GNUC__ + #define LIBXMLPP_VISIBILITY_DEFAULT __attribute__((visibility("default"))) + #define LIBXMLPP_MEMBER_METHOD + #endif #elif !defined (__GNUC__) #define LIBXMLPP_API __declspec(dllimport) #else /* don't dllimport classes/methods on GCC/MinGW */ @@ -34,5 +38,12 @@ #define LIBXMLPP_API #endif /* GLIBMM_DLL */ +#ifndef LIBXMLPP_VISIBILITY_DEFAULT + #define LIBXMLPP_VISIBILITY_DEFAULT +#endif +#ifndef LIBXMLPP_MEMBER_METHOD + #define LIBXMLPP_MEMBER_METHOD LIBXMLPP_API +#endif + #endif /* _LIBXMLPP_CONFIG_H */ diff --git a/libxml++config.h.meson b/libxml++config.h.meson index 2a5f03b2..d1b06ccb 100755 --- a/libxml++config.h.meson +++ b/libxml++config.h.meson @@ -26,6 +26,10 @@ #ifdef LIBXMLPP_DLL #ifdef LIBXMLPP_BUILD #define LIBXMLPP_API __declspec(dllexport) + #ifdef __GNUC__ + #define LIBXMLPP_VISIBILITY_DEFAULT __attribute__((visibility("default"))) + #define LIBXMLPP_MEMBER_METHOD + #endif #elif !defined (__GNUC__) #define LIBXMLPP_API __declspec(dllimport) #else /* don't dllimport classes/methods on GCC/MinGW */ @@ -36,5 +40,12 @@ #define LIBXMLPP_API #endif /* GLIBMM_DLL */ +#ifndef LIBXMLPP_VISIBILITY_DEFAULT + #define LIBXMLPP_VISIBILITY_DEFAULT +#endif +#ifndef LIBXMLPP_MEMBER_METHOD + #define LIBXMLPP_MEMBER_METHOD LIBXMLPP_API +#endif + #endif /* _LIBXMLPP_CONFIG_H */