On 07/30/2015 05:17 PM, Roger Leigh wrote:
> Are the duplicated template exports here at the level of the translation 
> unit not elided when linking the DLL?  In the dlltest git repo, I 
> specifically create DLLs with duplicate template exports in different 
> translation units to make sure it doesn't error out, and it appears to 
> cope.  I haven't checked on whether it removed duplicates from the 
> linked objects though--is this even possible?  I thought all current 
> toolchains were able to eliminate duplicate instantiations, or else 
> you'd have massive explosions of duplicate templates common across all 
> translation units.  Given the backwardness of the Windows linker, it 
> wouldn't surprise me if it were true though...

I'm not an expert on the MS linker, but at least some toolchains
treat implicit template instantiations as weak (W) symbols and
explicit template instantiations as normal (T) symbols.  Linkers
will resolve duplicate W symbols but allow only one T symbol.

Regardless, it is inefficient to ask the compiler to repeatedly
do an explicit instantiation when only one is needed.  I've seen
projects that keep each explicit instantiation in a dedicated
translation unit so that when one .o is needed for its instantiation
it doesn't force bringing in a bunch of other instantiations from
the same object.  With the instantiate-in-header approach then all
the objects in your library will instantiate all the templates
whose headers they include.  If the header always does the "extern"
explicit instantiation then the compiler does not need to do the
instantiation in any of the objects except the dedicated one.

-Brad
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

Reply via email to