Skip to content

Commit ad86850

Browse files
committed
BUG: Fix constexpr linkage issue
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.
1 parent 3e27a46 commit ad86850

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Modules/Core/Common/include/itkBSplineInterpolationWeightFunction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class ITK_TEMPLATE_EXPORT BSplineInterpolationWeightFunction
8787

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

9192
/** Evaluate the weights at specified ContinuousIndex position.
9293
* Subclasses must provide this method. */

Modules/Core/Common/include/itkBSplineInterpolationWeightFunction.hxx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@
2626

2727
namespace itk
2828
{
29+
30+
#if __cplusplus < 201703L
31+
// For compatibility with pre C++17 International Standards, a constexpr static
32+
// data member may be redundantly redeclared outside the class with no
33+
// initializer. This usage is deprecated.
34+
//
35+
// For C++14 and earlier, the definition of static constexpr must be outside of
36+
// class until C++17, see .h file for declaration & initialization
37+
38+
template <typename TCoordRep, unsigned int VSpaceDimension, unsigned int VSplineOrder>
39+
constexpr typename BSplineInterpolationWeightFunction<TCoordRep, VSpaceDimension, VSplineOrder>::SizeType
40+
BSplineInterpolationWeightFunction<TCoordRep, VSpaceDimension, VSplineOrder>::SupportSize;
41+
#endif
42+
2943
/** Compute weights for interpolation at continuous index position */
3044
template <typename TCoordRep, unsigned int VSpaceDimension, unsigned int VSplineOrder>
3145
typename BSplineInterpolationWeightFunction<TCoordRep, VSpaceDimension, VSplineOrder>::WeightsType

0 commit comments

Comments
 (0)