[CMake] Making and using static and shared libraries on Windows with Visual Studio

rleigh at codelibre.net rleigh at codelibre.net
Thu Jul 30 10:29:34 EDT 2015


> Did you try to remove all the explicit template exports? I never had to do
> it and compiled many static and shared libraries on Windows. Of course VS
> is going to complain about exporting template classes but as long as you
> don't try to mix VS versions I think you can safely ingore those warnings.

Thanks for the suggestions.  The above seems true, though I think I'll
likely retain it for DLL builds and lose it for static builds.  If nothing
else it removes the warnings and will hopefully make it safer for
corner-case failures by end users of the library?  Hopefully MSVC is
clever enough to elide duplicate instantiations when it links the DLL?

Relating to CMake, the guidance from Microsoft for correctly exporting
templates here: https://support.microsoft.com/en-us/kb/168958
uses an foo_EXPORT_TEMPLATE macro in addition to foo_EXPORT.  This is
basically empty in the DLL for export, and "extern" for imports.  I wonder
if this is something that GenerateExportHeader should be generating in
addition to the typical export macro?


Regards,
Roger



More information about the CMake mailing list