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

**URL:** <https://discourse.slicer.org/t/cannot-compile-slicer-on-mac-macos-sierra-clang-9-cmake-3-9-1/1104>\
**Category:** Development\
**Tags:** build\
**Created:** [September 22, 2017, 6:27pm UTC](https://discourse.slicer.org/t/cannot-compile-slicer-on-mac-macos-sierra-clang-9-cmake-3-9-1/1104 "2017-09-22T18:27:59Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![fedorov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fedorov/32/14_2.png) [@fedorov](https://discourse.slicer.org/u/fedorov)\
**Post date:** [September 22, 2017, 6:27pm UTC](https://discourse.slicer.org/t/cannot-compile-slicer-on-mac-macos-sierra-clang-9-cmake-3-9-1/1104/1 "2017-09-22T18:27:59Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/f/8/f8b6e55fffe81f63d670ee797775ab2caa1b2c5a.png)

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](https://www.slicer.org/wiki/Documentation/Nightly/Developers/Build_Instructions#Unix-like).

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:

```plaintext
$ 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

```

---

<div class="post-metadata">

**Author:** ![blowekamp](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/blowekamp/32/1386_2.png) [@blowekamp](https://discourse.slicer.org/u/blowekamp)\
**Post date:** [September 22, 2017, 6:59pm UTC](https://discourse.slicer.org/t/cannot-compile-slicer-on-mac-macos-sierra-clang-9-cmake-3-9-1/1104/2 "2017-09-22T18:59:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![fedorov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fedorov/32/14_2.png) [@fedorov](https://discourse.slicer.org/u/fedorov)\
**Post date:** [September 22, 2017, 7:22pm UTC](https://discourse.slicer.org/t/cannot-compile-slicer-on-mac-macos-sierra-clang-9-cmake-3-9-1/1104/3 "2017-09-22T19:22:31Z")

</div>

@blowekamp I confirm I have that entry:

```nohighlight
$ 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](https://discourse.slicer.org/t/transition-to-vtk-8-0/379/4)

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [September 22, 2017, 7:22pm UTC](https://discourse.slicer.org/t/cannot-compile-slicer-on-mac-macos-sierra-clang-9-cmake-3-9-1/1104/4 "2017-09-22T19:22:53Z")

</div>

> [@fedorov](#):
>
> Did anything relevant change recently in Slicer?

Based on comment of @blowekamp [here](https://github.com/SimpleITK/SimpleITK/issues/260#issuecomment-327180550), starting with [r26340](http://viewvc.slicer.org/viewvc.cgi/Slicer4/trunk/SuperBuild/External_SimpleITK.cmake?r1=26340&r2=26339&pathrev=26340) 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 ?

---

<div class="post-metadata">

**Author:** ![fedorov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fedorov/32/14_2.png) [@fedorov](https://discourse.slicer.org/u/fedorov)\
**Post date:** [September 22, 2017, 7:29pm UTC](https://discourse.slicer.org/t/cannot-compile-slicer-on-mac-macos-sierra-clang-9-cmake-3-9-1/1104/5 "2017-09-22T19:29:59Z")

</div>

> [@jcfr](#):
>
> we now explicitly pass CMAKE\_CXX\_STANDARD

I confirm it is set to 98 in SimpleITK cache:

```plaintext
$ 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](https://discourse.slicer.org/t/transition-to-vtk-8-0/379/4)), I guess I am being forced to switch to VTKv8 😉 I will try that next.

---

<div class="post-metadata">

**Author:** ![fedorov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fedorov/32/14_2.png) [@fedorov](https://discourse.slicer.org/u/fedorov)\
**Post date:** [September 22, 2017, 7:33pm UTC](https://discourse.slicer.org/t/cannot-compile-slicer-on-mac-macos-sierra-clang-9-cmake-3-9-1/1104/6 "2017-09-22T19:33:19Z")

</div>

If I switch to VTKv8, I get compile error in LibArchive ☹

```nohighlight
[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.

```

---

<div class="post-metadata">

**Author:** ![blowekamp](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/blowekamp/32/1386_2.png) [@blowekamp](https://discourse.slicer.org/u/blowekamp)\
**Post date:** [September 22, 2017, 7:45pm UTC](https://discourse.slicer.org/t/cannot-compile-slicer-on-mac-macos-sierra-clang-9-cmake-3-9-1/1104/7 "2017-09-22T19:45:50Z")

</div>

I am guessing that this patch:  
[https://github.com/Slicer/Slicer/commit/fb11a9a147568e283ef25dd4555617ec399dfd2d#diff-109aeb3808fbb9cd5a014863e7556a16](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.

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [September 22, 2017, 8:25pm UTC](https://discourse.slicer.org/t/cannot-compile-slicer-on-mac-macos-sierra-clang-9-cmake-3-9-1/1104/8 "2017-09-22T20:25:31Z")

</div>

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](https://issues.slicer.org/view.php?id=4434)

> 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](https://github.com/SimpleITK/SimpleITK/issues/260#issuecomment-327180550))

> 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](https://github.com/Slicer/Slicer/blob/ac3a3faba26e9536ce58a5832d5bf67cabf2d93a/CMakeLists.txt#L7-L21)

> [@fedorov](#):
>
> If I switch to VTKv8, I get compile error in LibArchive

This was reported by @pieper and is tracked in [LibArchive: cannot build with deployment target 10.9 · Issue #4438 · Slicer/Slicer · GitHub](https://issues.slicer.org/view.php?id=4438)

---

<div class="post-metadata">

**Author:** ![blowekamp](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/blowekamp/32/1386_2.png) [@blowekamp](https://discourse.slicer.org/u/blowekamp)\
**Post date:** [September 22, 2017, 8:34pm UTC](https://discourse.slicer.org/t/cannot-compile-slicer-on-mac-macos-sierra-clang-9-cmake-3-9-1/1104/9 "2017-09-22T20:34:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [September 22, 2017, 8:45pm UTC](https://discourse.slicer.org/t/cannot-compile-slicer-on-mac-macos-sierra-clang-9-cmake-3-9-1/1104/10 "2017-09-22T20:45:00Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![blowekamp](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/blowekamp/32/1386_2.png) [@blowekamp](https://discourse.slicer.org/u/blowekamp)\
**Post date:** [September 22, 2017, 9:33pm UTC](https://discourse.slicer.org/t/cannot-compile-slicer-on-mac-macos-sierra-clang-9-cmake-3-9-1/1104/11 "2017-09-22T21:33:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [September 22, 2017, 10:16pm UTC](https://discourse.slicer.org/t/cannot-compile-slicer-on-mac-macos-sierra-clang-9-cmake-3-9-1/1104/12 "2017-09-22T22:16:15Z")

</div>

> [@blowekamp](#):
>
> If using libc++ then C++11 is required.

Gotcha.

And this is the case when targeting macOS \> 10.9

---

<div class="post-metadata">

**Author:** ![blowekamp](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/blowekamp/32/1386_2.png) [@blowekamp](https://discourse.slicer.org/u/blowekamp)\
**Post date:** [September 25, 2017, 8:03pm UTC](https://discourse.slicer.org/t/cannot-compile-slicer-on-mac-macos-sierra-clang-9-cmake-3-9-1/1104/13 "2017-09-25T20:03:20Z")

</div>

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.

> [@jcfr](#):
>
> My understand is that c++98 matches the case where nothing was explicitly specified. And this seems to be a reasonable choic

I [think](https://stackoverflow.com/questions/21221411/when-will-gnu-c-support-c11-without-explicitly-asking-for-it) 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](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:

> <https://github.com/SimpleITK/SimpleITK/pull/302>

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.

---

<div class="post-metadata">

**Author:** ![fedorov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fedorov/32/14_2.png) [@fedorov](https://discourse.slicer.org/u/fedorov)\
**Post date:** [September 25, 2017, 10:11pm UTC](https://discourse.slicer.org/t/cannot-compile-slicer-on-mac-macos-sierra-clang-9-cmake-3-9-1/1104/14 "2017-09-25T22:11:52Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [September 25, 2017, 11:31pm UTC](https://discourse.slicer.org/t/cannot-compile-slicer-on-mac-macos-sierra-clang-9-cmake-3-9-1/1104/15 "2017-09-25T23:31:47Z")

</div>

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

As soon as I finalize Slicer [PR#796](https://github.com/Slicer/Slicer/pull/796) , most likely tonight, I will get to this.

@fedorov Thanks for your patience

---

<div class="post-metadata">

**Author:** ![blowekamp](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/blowekamp/32/1386_2.png) [@blowekamp](https://discourse.slicer.org/u/blowekamp)\
**Post date:** [September 27, 2017, 1:36pm UTC](https://discourse.slicer.org/t/cannot-compile-slicer-on-mac-macos-sierra-clang-9-cmake-3-9-1/1104/16 "2017-09-27T13:36:01Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![fedorov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fedorov/32/14_2.png) [@fedorov](https://discourse.slicer.org/u/fedorov)\
**Post date:** [September 27, 2017, 2:54pm UTC](https://discourse.slicer.org/t/cannot-compile-slicer-on-mac-macos-sierra-clang-9-cmake-3-9-1/1104/17 "2017-09-27T14:54:04Z")

</div>

> [@blowekamp](#):
>
> 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](https://issues.slicer.org/view.php?id=4438). Just to save the time for anyone following this thread.

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [September 29, 2017, 3:52pm UTC](https://discourse.slicer.org/t/cannot-compile-slicer-on-mac-macos-sierra-clang-9-cmake-3-9-1/1104/18 "2017-09-29T15:52:04Z")

</div>

@fedorov The LibArchive issue should be addressed in

> <https://github.com/Slicer/Slicer/issues/801>
>
> This issue was created automatically from an original Mantis Issue. Further discussion may take place here.

Thanks for @ihnorton for suggesting the update.

---

<div class="post-metadata">

**Author:** ![fedorov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fedorov/32/14_2.png) [@fedorov](https://discourse.slicer.org/u/fedorov)\
**Post date:** [October 2, 2017, 2:42pm UTC](https://discourse.slicer.org/t/cannot-compile-slicer-on-mac-macos-sierra-clang-9-cmake-3-9-1/1104/19 "2017-10-02T14:42:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [October 2, 2017, 2:44pm UTC](https://discourse.slicer.org/t/cannot-compile-slicer-on-mac-macos-sierra-clang-9-cmake-3-9-1/1104/20 "2017-10-02T14:44:09Z")

</div>

> [@fedorov](#):
>
> I disabled SimpleITK and will report if the overall build is successful.

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

[Next page](https://discourse.slicer.org/t/cannot-compile-slicer-on-mac-macos-sierra-clang-9-cmake-3-9-1/1104.md?page=2)
