Cannot compile Slicer on Mac - macOS Sierra + clang 9 + cmake 3.9.1

I recently had to reinstall the OS on my Mac, and since then I cannot compile Slicer due to this error:

image

I installed Qt using the brew recipe, turned off TCL, and set deployment target to 10.11, following instructions Documentation/Nightly/Developers/Build Instructions - Slicer Wiki.

I also communicated with @blowekamp, and he said:

SimpleITK compiled with modern Apple Clang compiler requires either an old SDK ~10.6 for GNU’s stdlibc++, or required C++11 enabled. I am not sure how the defaults have changed recently for Slicer…

Did anything relevant change recently in Slicer?

Here’s relevant system info:

$ cmake --version
cmake version 3.9.1

CMake suite maintained and supported by Kitware (kitware.com/cmake).

$ gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.0.0 (clang-900.0.37)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

$ qmake -v
QMake version 2.01a
Using Qt version 4.8.7 in /usr/local/lib

For this case with OS X 10.11 SDK, and clang C+11 should be enabled for SimpleITK. This should happen automatically. This should be indicated in the configuration file by the following entry in the SimpleITK’s CMakeCache.txt:

SITK_CHECK_CXX11:STRING=FALSE

note: FALSE indicates that -stdc++=11 is required

@blowekamp I confirm I have that entry:

$ grep SITK_CHECK_CXX11 CMakeCache.txt
SITK_CHECK_CXX11:INTERNAL=FALSE

But @jcfr confirmed recently c++11 is not currently supported in Slicer: Transition to VTK 8.0

Based on comment of @blowekamp here, starting with r26340 we now explicitly pass CMAKE_CXX_STANDARD, CMAKE_CXX_STANDARD_REQUIRED and CMAKE_CXX_EXTENSIONS options.

@blowekamp Should we do things differently to support both C++98 and C++11 ?

I confirm it is set to 98 in SimpleITK cache:

$ grep -r CXX_STANDARD CMakeCache.txt
CMakeCache.txt:CMAKE_CXX_STANDARD:STRING=98
CMakeCache.txt:CMAKE_CXX_STANDARD_REQUIRED:BOOL=ON

But as @blowekamp said, C++11 is required.

Considering your comment in the above referenced thread (Transition to VTK 8.0 - #4 by jcfr), I guess I am being forced to switch to VTKv8 :wink: I will try that next.

If I switch to VTKv8, I get compile error in LibArchive :frowning:

[ 11%] Building C object libarchive/CMakeFiles/archive_static.dir/archive_read_disk_posix.c.o
/Users/fedorov/build/Slicer-Release/LibArchive/libarchive/archive_read_disk_posix.c:1984:6: error: 'futimens' is only available on macOS 10.13 or newer
      [-Werror,-Wunguarded-availability-new]
        if (futimens(fd, timespecs) == 0)
            ^~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/sys/stat.h:373:5: note: 'futimens' has been explicitly marked partial here
int     futimens(int __fd, const struct timespec __times[2]) __API_AVAILABLE(macosx(10.13), ios(11.0), tvos(11.0), watchos(4.0));
        ^
/Users/fedorov/build/Slicer-Release/LibArchive/libarchive/archive_read_disk_posix.c:1984:6: note: enclose 'futimens' in a __builtin_available check to silence this warning
        if (futimens(fd, timespecs) == 0)
            ^~~~~~~~
1 error generated.

I am guessing that this patch:
https://github.com/Slicer/Slicer/commit/fb11a9a147568e283ef25dd4555617ec399dfd2d#diff-109aeb3808fbb9cd5a014863e7556a16

Now for the slicer superbuild, is CMAKE_CXX_STANDARD:STRING=98 explicitly set or is in coming from the above patch when CMAKE_CXX_STANDARD is not defined and some kind of default is being set?

Currently SimpleITK just adds --stdc++=11 to the CMAKE_CXX_FLAGS since it (previously) works with all version of CMake. But is appears the CMAKE_CXX_STANDARD variable are overriding it. Atleast in these try compiles.

As a side note, failure to build SimpleITK using C++98 on recent macOS is already tracked in compatibility issue with osx · Issue #4434 · Slicer/Slicer · GitHub

it appears the CMAKE_CXX_STANDARD variable are overriding it.

Most likely, but I thought that using CMake > 3.8.2 is used (see here)

some kind of default is being set?

Default are set in the toplevel CMakeLists.txt where we explicitly requires CMake >3.8.2.

https://github.com/Slicer/Slicer/blob/ac3a3faba26e9536ce58a5832d5bf67cabf2d93a/CMakeLists.txt#L7-L21

This was reported by @pieper and is tracked in LibArchive: cannot build with deployment target 10.9 · Issue #4438 · Slicer/Slicer · GitHub

Friday after noon ramblings on this issue:

Further experimentation yields that if SimpleITK is configured with the CMAKE_CXX_STANDARD flags must not be null for CMAKE. Therefor I presume Slicers Superbuild is explicitly setting the standard. ( Why not c++03?)

I would consider not passing these CMAKE_CXX_STANDARD flags for this problematic case to SimpleITK. When on OS X, and the standard version is less that 11 and the OS X SDK is greater that 10.7? These flags should not be passed. This will enable SimpleITK to set the flag as need.

While SimpleITK could manipulate the CMAKE_CXX_STANARD flag for this case, because older cmake’s try_compile does not respect this option it would yield inconsistent and trouble prone behavior. There are a lot of factors that effect this situation… I’ll have to think about it further…

Compiling ITK with C++98 while compiling SimpleITK C++11, is not ideal, but all the tests seem to pass for the wrapping. The problem may be if SimpleITK C++ interface is used with this mixed standard configuration.

Compiling ITK with C++98 while compiling SimpleITK C++11, is not ideal, but all the tests seem to pass for the wrapping.

I see

Thanks for the details answer. Things are now clearer.

Since c++11 is a hard requirement for SimpleITK. I will update Slicer build system to not pass the CMAKE_CXX_STANDARD related options if building with C++98 (aka Qt4). That way the builtin logic of SimpleITK will be used to initialize the flags and always use c+11 …

Why not c++03?

My understand is that c++98 matches the case where nothing was explicitly specified. And this seems to be a reasonable choice.

If using libc++ then C++11 is required.

Gotcha.

And this is the case when targeting macOS > 10.9

Currently, Slicer is explicitly requesting C++98, and SimpleITK will not override that request even though it is not compatible in this configuration. I think that is reasonable behavior for SimpleITK when CMAKE_CXX_STANDARD(_REQUIRED is explicitly set, but for Slicer as a whole it does not work well.

I think that the GCC compilers default to the GNU dialect, and GCC 6 version default to gnu++14. So these options selected are having an effect. While on MSVC there does not seem to be a way to specify the C++ standard, it is just evolving with the releases.

While the logic needed to determine if C++11 is needed for SimpleITK can easily be said as: “If using libc++ then C++11 is required”, or “SimpleITK requires C++98 with TR1 or C++11”, it is harder to detect this case in CMake because of the interdependency of the ways to set C++ version, the OS X Deployment Target, and the CXX command line flags ( -stdlib=, -std=). I do have a try compile which checks for libc++ without C++11:https://github.com/SimpleITK/SimpleITK/blob/next/CMake/sitk_check_cxx11_required.cxx#L4

I have created a pull request that improves the situation in SimpleITK:

It handles CMake CXX standard flags for older versions of CMake and gives better error messages when the C++ version is not able to be set as needed. For this case it would produce the following message:

CMake Error at CMake/sitkCheckCXX11.cmake:110 (message):
SimpleITK requires usage of C++11 or C++ Technical Report 1 (TR1), but were
neither able to detect TR1 nor automatically enable C++11. Please review
your configuration settings and enable C++11.

Let me know if there is anything that I could try.

Meanwhile, I am compiling Slicer with SDK 10.13 and with SimpleITK disabled.

@blowekamp It all makes sense, I just didn’t have a chance to get to this.

As soon as I finalize Slicer PR#796 , most likely tonight, I will get to this.

@fedorov Thanks for your patience

With the current state of things in Slicer with OS X, I believe the easiest way currently to get things to build with SimpleITK is to set CMAKE_OSX_DEPLOYMENT_TARGET=10.8.

Not really - due to another issue, superbuild will fail in LibArchive with SDK earlier than 10.13: LibArchive: cannot build with deployment target 10.9 · Issue #4438 · Slicer/Slicer · GitHub. Just to save the time for anyone following this thread.

@fedorov The LibArchive issue should be addressed in

Thanks for @ihnorton for suggesting the update.

1 Like

Thank you JC! I confirm LibArchive can now be compiled on SDK 10.13. I disabled SimpleITK and will report if the overall build is successful.

1 Like

Sounds good. The SimpleITK build issue will be addressed this week.