[cmake-developers] [patch] Export template instantiations with GenerateExportHeader

Brad King brad.king at kitware.com
Thu Jul 30 13:34:27 EDT 2015


On 07/30/2015 11:23 AM, Roger Leigh wrote:
> foo_EXPORT_TEMPLATE template class foo_EXPORT std::allocator<char>;
[snip]
>  #    ifdef @EXPORT_IMPORT_CONDITION@
>          /* We are building this library */
>  #      define @EXPORT_MACRO_NAME@ @DEFINE_EXPORT@
> +#      define @EXPORT_MACRO_NAME at _TEMPLATE
>  #    else
>          /* We are using this library */
>  #      define @EXPORT_MACRO_NAME@ @DEFINE_IMPORT@
> +#      define @EXPORT_MACRO_NAME at _TEMPLATE extern
>  #    endif
[snip]
> Note that I'm by no means a Windows C++ or DLL expert--I'm primarily a 
> C++ UNIX developer--this is just from reading the docs and experimenting.

The problem with this approach is that the non-extern explicit
template instantiation should not be done in the header file
because if more than one source file in a single library includes
the header then each of those object files will provide the
explicit instantiation.  Only one source should provide the symbols.

So, one actually wants the "extern" to appear in the header
file in all cases except when included in *one* specific
source file within the library.  For this there needs to
be an identifying macro associated with the source file.
Therefore it does not make sense for this macro to be defined
as part of GenerateExportHeader because that generates macros
that switch off of library-level conditions.

-Brad



More information about the cmake-developers mailing list