[Trilinos-Users] Question About Template Specialization in .hpp Files

Corey A. Henderson cahenderson at wisc.edu
Sat Nov 5 18:30:42 EDT 2016


I recently chased down a linker problem in a code I'm writing, where I
was getting "multiple definition" errors when I added
MueLu_CreateEpetraPreconditioner.hpp. Specifically
CreateEpetraPreconditioner and ReuseEpetraPreconditioner. I was able
to work around it by ensuring I only include this .hpp file from one
compilation unit, but in researching my problem I learned that
template specializations shouldn't be in .hpp files for this very
reason.

EG: http://stackoverflow.com/questions/4445654/multiple-definition-of-template-specialization-when-using-different-objects

So far as I can tell (Trilinos v12.8.1) there is no way to include
this .hpp file in two different compilation units successfully. I did
configure Trilinos with the Trilinos_ENABLE_EXPLICIT_INSTANTIATION
option ON. I'm not sure if that makes a difference.

Should this code (the template specializations) be in a .cpp file and
thus in the libraries? Or am I missing something?

Corey

-- 
Corey A. Henderson
PhD Candidate and NSF Graduate Fellow
Dept. of Engineering Physics
Univ. of Wisconsin - Madison


More information about the Trilinos-Users mailing list