Hello World from ITK/Examples/Installation/ not compiling for ITK 5.3

Here is the error message that was popping up on my Mac OSX Big Sur (Apple clang version 12.0.5 (clang-1205.0.22.11)).

I fixed it by changing the CMakeLists.txt file. Wanted to post here incase other beginners face the same issue.

bash-3.2$ make
[ 50%] Building CXX object CMakeFiles/HelloWorld.dir/HelloWorld.cxx.o
In file included from /Users/veritas/GITROOT/ITIA/HelloWorld.cxx:27:
In file included from /Users/veritas/GITROOT/ITK/Modules/Core/Common/include/itkImage.h:21:
In file included from /Users/veritas/GITROOT/ITK/Modules/Core/Common/include/itkImageRegion.h:31:
In file included from /Users/veritas/GITROOT/ITK/Modules/Core/Common/include/itkRegion.h:31:
In file included from /Users/veritas/GITROOT/ITK/Modules/Core/Common/include/itkObject.h:31:
In file included from /Users/veritas/GITROOT/ITK/Modules/Core/Common/include/itkLightObject.h:21:
In file included from /Users/veritas/GITROOT/ITK/Modules/Core/Common/include/itkMacro.h:42:
/Users/veritas/bin/GITROOT/itk/Modules/Core/Common/itkConfigure.h:56:6: warning: "WARNING:  The current project is configured to use a C++ standard version older than the C++ standard used for this build of ITK" [-W#warnings]
    #warning "WARNING:  The current project is configured to use a C++ standard version older than the C++ standard used for this build of ITK"
     ^
In file included from /Users/veritas/GITROOT/ITIA/HelloWorld.cxx:27:
In file included from /Users/veritas/GITROOT/ITK/Modules/Core/Common/include/itkImage.h:21:
In file included from /Users/veritas/GITROOT/ITK/Modules/Core/Common/include/itkImageRegion.h:31:
In file included from /Users/veritas/GITROOT/ITK/Modules/Core/Common/include/itkRegion.h:31:
In file included from /Users/veritas/GITROOT/ITK/Modules/Core/Common/include/itkObject.h:31:
In file included from /Users/veritas/GITROOT/ITK/Modules/Core/Common/include/itkLightObject.h:21:
/Users/veritas/GITROOT/ITK/Modules/Core/Common/include/itkMacro.h:192:6: error: "Apple LLVM < 5.1 (clang < 3.4) or compiling with a standard less than C++14 is not supported under ITKv5.3"
#    error "Apple LLVM < 5.1 (clang < 3.4) or compiling with a standard less than C++14 is not supported under ITKv5.3"
     ^

Solution:

Add the following to your CMakeLists.txt file

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

Maybe make a Pull Request fixing the code?

Are you getting the example from the main repository or someplace else?

HI Dzenan,

I picked up the example from the github release branch with that path, created a new build folder, just copied over the CMakeLists and cxx file. Also used the latest version of cmake.

Kishore

BTW, I had the same problem come up when I compiled ITKSphinxExamples. I had to change the CMakeLists.txt file as follows:

if(NOT CMAKE_CXX_STANDARD)

set(CMAKE_CXX_STANDARD 14) # Supported values are 11, 14, and 17 .

endif()

I had to change the CMAKE_CXX_STANDARD from 11 to 14.

Kishore

Default standard is compiler-dependent. Older compilers have older defaults. Which compiler are you using?

PR 2757 adds it to the example in the main repo.

@jhlegarreta @matt.mccormick should we do similar changes to ITKSphinxExamples?

Here is what I get as gcc version:
bash-3.2$ gcc --version

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.5 (clang-1205.0.22.11)
Target: x86_64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

On the one hand, I’m wondering whether it makes sense/it is possible to inherit the flags from the upstream CMake files where the values are originally set. On the other hand, that example is just to illustrate a minimal CMakeLists.txt file in here (section 2.5.1; https://itk.org/ItkSoftwareGuide.pdf) (looks like the contents are outdated, and the file is not being read), so I’m not sure of the benefit of inheriting the flags.

Concerning the ITKSphinxExamples, it looks like the flags are being set to a value that is different from ITK, which might be fine unless there is a clash when using the SuperBuild. But it looks counter-intuitive to require a different version in the ITKSphinxExamples.

Looks like I don’t have a clear answer to this.

ITKSphinxExamples has not been updated to ITK 5.3 yet, so it still has the old CXX standard and version of CMake.

Each example in there is supposed to be standalone, that’s why it has so much duplication.

@krm15 is using an unusual “compiler” (clang pretending to be GCC?), that’s why it might be defaulting to such an old version of C++ standard. I don’t know how prevalent such occurrence is. Also, the provided error message is clear and easily fixed for those who run into it.

:+1:. I am in favor of updating the ITKSphinxExamples. Matt may be in a better position to provide favourable/against arguments.

:+1:. Not sure next time the C++ standard is updated the CMAKE_CXX_STANDARD will be hit, and if it is, the contributor will update it (other hits corresponding to 3rd parties should be left apart), so maybe adding a note somewhere about updating C++ standards in general and the CMAKE_CXX_STANDARD flag in particular, could be a good idea/candidate for a documentation issue.

True, but at the same time:

  • I ignore how unusual these situations are.
  • I think it is preferable not to allow Examples/Installation to fail.

So to me the PR is reasonable.

1 Like

@krm15 thanks for the report!

So existing code can work without modification, please review this patch:

As @dzenanz @jhlegarreta noted, we do not want to add additional burden to any client projects as demonstrated with the examples when upgrading ITK.

1 Like