From 93c59c78b09a835f87100c920e430b30e94abb37 Mon Sep 17 00:00:00 2001 From: Joris Vaillant Date: Thu, 18 Jan 2024 11:38:36 +0100 Subject: [PATCH 1/2] [config.hh] Try to fix explicit template instantiation warning on Windows --- config.hh.cmake | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/config.hh.cmake b/config.hh.cmake index ad3f92f7e..a6e79b8c8 100644 --- a/config.hh.cmake +++ b/config.hh.cmake @@ -32,32 +32,33 @@ // On Linux, set the visibility accordingly. If C++ symbol visibility // is handled by the compiler, see: http://gcc.gnu.org/wiki/Visibility // -// Also define explicit template instantiation keyword -// This keyword should be extern template but when mixed with -// dllexport on Windows this generate a warning. -// The extern keyword is then remove when mixed with dllexport. +// Explicit template instantiation on Windows need to add +// dllexport on the definition and dllimport on the declaration. +// The XXX_EXPLICIT_INSTANTIATION_DECLARATION_DLLAPI macro +// should be set on the declaration while the XXX_DLLAPI macro +// should be set on the definition. # if defined _WIN32 || defined __CYGWIN__ // On Microsoft Windows, use dllimport and dllexport to tag symbols. # define @LIBRARY_NAME@_DLLIMPORT __declspec(dllimport) # define @LIBRARY_NAME@_DLLEXPORT __declspec(dllexport) # define @LIBRARY_NAME@_DLLLOCAL -# define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DECLARATION_IMPORT extern template -# define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DECLARATION_EXPORT template +# define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DECLARATION_DLLIMPORT __declspec(dllimport) +# define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DECLARATION_DLLEXPORT # else // On Linux, for GCC >= 4, tag symbols using GCC extension. # if __GNUC__ >= 4 # define @LIBRARY_NAME@_DLLIMPORT __attribute__ ((visibility("default"))) # define @LIBRARY_NAME@_DLLEXPORT __attribute__ ((visibility("default"))) # define @LIBRARY_NAME@_DLLLOCAL __attribute__ ((visibility("hidden"))) -# define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DECLARATION_IMPORT extern template -# define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DECLARATION_EXPORT extern template +# define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DECLARATION_DLLIMPORT __attribute__ ((visibility("default"))) +# define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DECLARATION_DLLEXPORT __attribute__ ((visibility("default"))) # else // Otherwise (GCC < 4 or another compiler is used), export everything. # define @LIBRARY_NAME@_DLLIMPORT # define @LIBRARY_NAME@_DLLEXPORT # define @LIBRARY_NAME@_DLLLOCAL -# define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DECLARATION_IMPORT extern template -# define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DECLARATION_EXPORT extern template +# define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DECLARATION_DLLIMPORT +# define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DECLARATION_DLLEXPORT # endif // __GNUC__ >= 4 # endif // defined _WIN32 || defined __CYGWIN__ @@ -74,10 +75,10 @@ // define the right explicit template instantiation keyword. # ifdef @EXPORT_SYMBOL@ # define @LIBRARY_NAME@_DLLAPI @LIBRARY_NAME@_DLLEXPORT -# define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DECLARATION @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DECLARATION_EXPORT +# define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DECLARATION_DLLAPI @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DECLARATION_DLLEXPORT # else # define @LIBRARY_NAME@_DLLAPI @LIBRARY_NAME@_DLLIMPORT -# define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DECLARATION @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DECLARATION_IMPORT +# define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DECLARATION_DLLAPI @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DECLARATION_DLLIMPORT # endif // @LIBRARY_NAME@_EXPORTS # define @LIBRARY_NAME@_LOCAL @LIBRARY_NAME@_DLLLOCAL # endif // @LIBRARY_NAME@_STATIC From decfff2f515623c127671e5d7643e533cf1e4fad Mon Sep 17 00:00:00 2001 From: Joris Vaillant Date: Thu, 18 Jan 2024 15:50:16 +0100 Subject: [PATCH 2/2] [config.hh] Add XXX_EXPLICIT_INSTANTIATION_DEFINITION_DLLAPI macro --- config.hh.cmake | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/config.hh.cmake b/config.hh.cmake index a6e79b8c8..d3b4a367b 100644 --- a/config.hh.cmake +++ b/config.hh.cmake @@ -35,7 +35,8 @@ // Explicit template instantiation on Windows need to add // dllexport on the definition and dllimport on the declaration. // The XXX_EXPLICIT_INSTANTIATION_DECLARATION_DLLAPI macro -// should be set on the declaration while the XXX_DLLAPI macro +// should be set on the declaration while +// the XXX_EXPLICIT_INSTANTIATION_DEFINITION_DLLAPI macro // should be set on the definition. # if defined _WIN32 || defined __CYGWIN__ // On Microsoft Windows, use dllimport and dllexport to tag symbols. @@ -44,6 +45,8 @@ # define @LIBRARY_NAME@_DLLLOCAL # define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DECLARATION_DLLIMPORT __declspec(dllimport) # define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DECLARATION_DLLEXPORT +# define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DEFINITION_DLLIMPORT __declspec(dllimport) +# define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DEFINITION_DLLEXPORT __declspec(dllexport) # else // On Linux, for GCC >= 4, tag symbols using GCC extension. # if __GNUC__ >= 4 @@ -52,6 +55,8 @@ # define @LIBRARY_NAME@_DLLLOCAL __attribute__ ((visibility("hidden"))) # define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DECLARATION_DLLIMPORT __attribute__ ((visibility("default"))) # define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DECLARATION_DLLEXPORT __attribute__ ((visibility("default"))) +# define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DEFINITION_DLLIMPORT +# define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DEFINITION_DLLEXPORT # else // Otherwise (GCC < 4 or another compiler is used), export everything. # define @LIBRARY_NAME@_DLLIMPORT @@ -59,6 +64,8 @@ # define @LIBRARY_NAME@_DLLLOCAL # define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DECLARATION_DLLIMPORT # define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DECLARATION_DLLEXPORT +# define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DEFINITION_DLLIMPORT +# define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DEFINITION_DLLEXPORT # endif // __GNUC__ >= 4 # endif // defined _WIN32 || defined __CYGWIN__ @@ -76,9 +83,11 @@ # ifdef @EXPORT_SYMBOL@ # define @LIBRARY_NAME@_DLLAPI @LIBRARY_NAME@_DLLEXPORT # define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DECLARATION_DLLAPI @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DECLARATION_DLLEXPORT +# define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DEFINITION_DLLAPI @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DEFINITION_DLLEXPORT # else # define @LIBRARY_NAME@_DLLAPI @LIBRARY_NAME@_DLLIMPORT # define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DECLARATION_DLLAPI @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DECLARATION_DLLIMPORT +# define @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DEFINITION_DLLAPI @LIBRARY_NAME@_EXPLICIT_INSTANTIATION_DEFINITION_DLLIMPORT # endif // @LIBRARY_NAME@_EXPORTS # define @LIBRARY_NAME@_LOCAL @LIBRARY_NAME@_DLLLOCAL # endif // @LIBRARY_NAME@_STATIC