Skip to content

Commit fddcb23

Browse files
committed
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: #45
1 parent 2669b1f commit fddcb23

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

libxml++/exceptions/exception.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ namespace xmlpp
3636

3737
/** Base class for all xmlpp exceptions.
3838
*/
39-
class exception : public std::exception
39+
class LIBXMLPP_VISIBILITY_DEFAULT exception : public std::exception
4040
{
4141
public:
42-
LIBXMLPP_API
42+
LIBXMLPP_MEMBER_METHOD
4343
explicit exception(const ustring& message);
44-
LIBXMLPP_API ~exception() noexcept override;
44+
LIBXMLPP_MEMBER_METHOD ~exception() noexcept override;
4545

46-
LIBXMLPP_API const char* what() const noexcept override;
46+
LIBXMLPP_MEMBER_METHOD const char* what() const noexcept override;
4747

48-
LIBXMLPP_API virtual void raise() const;
49-
LIBXMLPP_API virtual exception* clone() const;
48+
LIBXMLPP_MEMBER_METHOD virtual void raise() const;
49+
LIBXMLPP_MEMBER_METHOD virtual exception* clone() const;
5050

5151
private:
5252
ustring message_;

libxml++config.h.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
#ifdef LIBXMLPP_DLL
2525
#ifdef LIBXMLPP_BUILD
2626
#define LIBXMLPP_API __declspec(dllexport)
27+
#ifdef __GNUC__
28+
#define LIBXMLPP_VISIBILITY_DEFAULT __attribute__((visibility("default")))
29+
#define LIBXMLPP_MEMBER_METHOD
30+
#endif
2731
#elif !defined (__GNUC__)
2832
#define LIBXMLPP_API __declspec(dllimport)
2933
#else /* don't dllimport classes/methods on GCC/MinGW */
@@ -34,5 +38,12 @@
3438
#define LIBXMLPP_API
3539
#endif /* GLIBMM_DLL */
3640

41+
#ifndef LIBXMLPP_VISIBILITY_DEFAULT
42+
#define LIBXMLPP_VISIBILITY_DEFAULT
43+
#endif
44+
#ifndef LIBXMLPP_MEMBER_METHOD
45+
#define LIBXMLPP_MEMBER_METHOD LIBXMLPP_API
46+
#endif
47+
3748
#endif /* _LIBXMLPP_CONFIG_H */
3849

libxml++config.h.meson

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
#ifdef LIBXMLPP_DLL
2727
#ifdef LIBXMLPP_BUILD
2828
#define LIBXMLPP_API __declspec(dllexport)
29+
#ifdef __GNUC__
30+
#define LIBXMLPP_VISIBILITY_DEFAULT __attribute__((visibility("default")))
31+
#define LIBXMLPP_MEMBER_METHOD
32+
#endif
2933
#elif !defined (__GNUC__)
3034
#define LIBXMLPP_API __declspec(dllimport)
3135
#else /* don't dllimport classes/methods on GCC/MinGW */
@@ -36,5 +40,12 @@
3640
#define LIBXMLPP_API
3741
#endif /* GLIBMM_DLL */
3842

43+
#ifndef LIBXMLPP_VISIBILITY_DEFAULT
44+
#define LIBXMLPP_VISIBILITY_DEFAULT
45+
#endif
46+
#ifndef LIBXMLPP_MEMBER_METHOD
47+
#define LIBXMLPP_MEMBER_METHOD LIBXMLPP_API
48+
#endif
49+
3950
#endif /* _LIBXMLPP_CONFIG_H */
4051

0 commit comments

Comments
 (0)