Search code examples
c++11clanghomebrewboost-hana

Clang 3.6.0 crashes trying to compile "hana/example/core/is_a.cpp"


Trying to compile Boost.Hana library from https://github.com/ldionne/hana latest sources (as of today). Getting a crash during make examples. Is it a problem with latest sources-compiler combination, or that I haven't really installed the required compiler version (Hana needs some latest bug fixes in Clang)? I'm fairly new to OS X, so struggled a bit with setting up compiler and the library, and don't know how to properly configure cmake to build with the newly installed clang.

I've installed clang via Homebrew:

brew install --HEAD llvm --with-clang

When I tried to make with just the newly installed compiler, build failed because it couldn't find "cstdio" header.

So then I've also cloned "libcxx" from github and changed a setting in CMakeCache.txt:

CMAKE_CXX_FLAGS:STRING=-Wall -std=c++11 -stdlib=libc++ -I/Users/yacoder/github/libcxx/include/

And here is a quote from the crash output I now get during make examples:

0.  Program arguments: /usr/local/Cellar/llvm/HEAD/bin/clang -cc1 -triple x86_64-apple-macosx10.9.0 -emit-obj -mrelax-all -disable-free -main-file-name is_a.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 241.8 -dwarf-column-info -coverage-file /Users/yacoder/github/hana/build/example/CMakeFiles/example.core.is_a.dir/core/is_a.cpp.o
-resource-dir /usr/local/Cellar/llvm/HEAD/bin/../lib/clang/3.6.0 -I /Users/yacoder/github/libcxx/include/ -I /Users/yacoder/github/hana/include -stdlib=libc++ -stdlib=libc++ -Wall
-W -Wall -Wextra -Wno-long-long -Wno-unused-local-typedefs -Wno-unused-parameter -Wwrite-strings -pedantic -std=c++1y -fdeprecated-macro -fdebug-compilation-dir /Users/yacoder/github/hana/build/example -ferror-limit 19
-fmessage-length 177 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.9.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o CMakeFiles/example.core.is_a.dir/core/is_a.cpp.o -x c++ /Users/yacoder/github/hana/example/core/is_a.cpp
1.  /Users/yacoder/github/hana/example/core/is_a.cpp:51:5: current parser token ')'
2.  /Users/yacoder/github/hana/example/core/is_a.cpp:26:12: parsing function body 'main'
3.  /Users/yacoder/github/hana/example/core/is_a.cpp:26:12: in compound statement ('{}') clang: error: unable to execute command: Segmentation fault: 11 clang: error: clang frontend command failed due to signal (use -v to see invocation) clang version 3.6.0 (trunk) Target: x86_64-apple-darwin13.4.0

Solution

  • Installing Clang through Homebrew should work just fine, as long as you use the --HEAD version. When building Clang, do make sure that you build in Release mode; otherwise some tests will trigger assertions in Clang (the bugs were reported long ago). I think the Release build is the default with Homebrew, so you have no action to take here.

    Then, you also need the latest version of libc++. Adding the include path like you did will work just fine. However, Hana needs to compile with -std=c++1y instead of std=c++11. Hana already passes the flags it needs to the compiler, so you should be OK if you leave them as is, except for the include path which needs to be modified for your libc++.

    Finally, you should use make -k instead of make. This instructs make to keep going even when there are errors. The thing is that Clang trunk still has several C++14-related bugs causing it to segfault/assert/explode on some tests. In particular, core/example/is_a.cpp has been failing intermittently for the past week or so. All in all, you should expect 3-4 assertions while running the tests. This sucks, but the Clang guys have been made aware of those problems.

    TL;DR

    Try the following:

    > cd root/of/hana
    > mkdir build && cd build
    > CXX=path/to/clang/binary cmake .. -DCMAKE_CXX_FLAGS="-I path/to/libc++"
    > make -k
    

    If you installed Clang with Homebrew, path/to/clang/binary is probably something like /usr/local/opt/llvm/bin/clang++.