Skip to content

Commit

Permalink
BUG: Fix constexpr linkage issue
Browse files Browse the repository at this point in the history
Reason: Prior to C++17 one must  provide the definition of the static
constexpr member as well as the declaration. The declaration and the
initializer go inside the class definition, but the member definition
has to be separate.

FAILED: bin/ITKCommon2TestDriver
Undefined symbols for architecture x86_64:
  "itk::BSplineInterpolationWeightFunction<float, 2u, 1u>::SupportSize", referenced from:
      itk::BSplineInterpolationWeightFunction<float, 2u, 1u>::GetSupportSize() const in itkBSplineInterpolationWeightFunctionTest.cxx.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[1081/1334] Building CXX object Modules/Registration/RegistrationMethodsv4/test/CMakeFiles/ITKRegistrationMethodsv4TestDriver.dir/itkSimpleImageRegistrationTestWithMaskAndSampling.cxx.o
ninja: build stopped: subcommand failed.
  • Loading branch information
hjmjohnson committed Nov 11, 2021
1 parent 3e27a46 commit ad86850
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Expand Up @@ -87,6 +87,7 @@ class ITK_TEMPLATE_EXPORT BSplineInterpolationWeightFunction

/** The support region size: a hypercube of length SplineOrder + 1 */
static constexpr SizeType SupportSize{ SizeType::Filled(VSplineOrder + 1) };
// Declaration here, definition must be outside of class until C++17, see .hxx file for linker definition

/** Evaluate the weights at specified ContinuousIndex position.
* Subclasses must provide this method. */
Expand Down
Expand Up @@ -26,6 +26,20 @@

namespace itk
{

#if __cplusplus < 201703L
// For compatibility with pre C++17 International Standards, a constexpr static
// data member may be redundantly redeclared outside the class with no
// initializer. This usage is deprecated.
//
// For C++14 and earlier, the definition of static constexpr must be outside of
// class until C++17, see .h file for declaration & initialization

template <typename TCoordRep, unsigned int VSpaceDimension, unsigned int VSplineOrder>
constexpr typename BSplineInterpolationWeightFunction<TCoordRep, VSpaceDimension, VSplineOrder>::SizeType
BSplineInterpolationWeightFunction<TCoordRep, VSpaceDimension, VSplineOrder>::SupportSize;
#endif

/** Compute weights for interpolation at continuous index position */
template <typename TCoordRep, unsigned int VSpaceDimension, unsigned int VSplineOrder>
typename BSplineInterpolationWeightFunction<TCoordRep, VSpaceDimension, VSplineOrder>::WeightsType
Expand Down

0 comments on commit ad86850

Please sign in to comment.