[Insight-developers] Link errors and itk::NumericTraits on Windows

Zachary Pincus zpincus at stanford.edu
Thu Apr 6 14:36:35 EDT 2006


> Zach,
>
> Please replace line 20 in itkRGBPixel.h with
> #include "itkNumericTraitsRGBPixel.h"
>
> and let us know if that fixes your wrapping issue.

That almost certainly will fix the particular issue that brought my  
attention to this problem. Now, to be clear, this is not a wrapping  
issue per se -- anyone who tries to compile and link (on windows)  
something like:

#include "itkConstantBoundaryCondition.h"
#include "itkRGBPixel.h"
itk::ConstantBoundaryCondition<itk::RGBPixel<unsigned char>, 2> >

will face strange link errors.

> IMHO this is how things should look.
>
> For instance:
>
> Pixel.h :
>   class Pixel{ ... };
>
> Pixel.txx
>  #include "NumericTraitsPixel.h"
>  #include "Pixel.h"
>  NumericTraitsPixel.h
>  #include "Pixel.h"
>  template <> NumericTraits< Pixel > { ... }
>
>
> IMHO that should how things should look. This is not what  
> RGBPixel.h/txx does and I think that's the bug. All the other  
> pixels (for instance VariableLengthVector.h/txx do this). I did not  
> have issues wrapping this class or classes that used this class.

OK, RGBPixel doesn't include NumericTraitsRGBPixel in the txx file,  
and CovariantVector doesn't include NumericTraitsCovariantVectorPixel  
in its txx. The other pixel types with NumericTraits specializations do.

(Note that many compound pixel type classes do include the vanilla  
NumericTraits.h in their headers, but that's to get access to the  
traits of the pixel component types like float or whatever, and isn't  
just a typo that should be replaced with #including the  
NumericTraitsXXXPixel.h file instead.)

Now, I would further argue that having the #include  
"itkNumericTraitsXXXPixel.h" in the txx file instead of the header  
file is a bug. Including the numeric traits specialization is clearly  
an interface issue (because it's needed for linking) and not an  
implementation issue. Thus, everything will break badly if explicit  
template instantiations are provided (preventing the txx files from  
being included by default).

I propose therefore that I will make the header files of all of the  
compound pixel types #include the appropriate NumericTraitsXXXPixel.h  
headers. Does this seem OK?

Zach






More information about the Insight-developers mailing list