Clang 3.6.0崩溃试图编译“hana / example / core / is_a.cpp”

时间:2014-10-19 02:34:14

标签: c++11 clang homebrew boost-hana

尝试从https://github.com/ldionne/hana最新来源(截至今天)编译Boost.Hana库。在make examples期间遇到崩溃。这是最新的源 - 编译器组合的问题,还是我还没有真正安装所需的编译器版本(Hana需要一些最新的错误修复)?我是OS X的新手,因此在设置编译器和库方面有点挣扎,并且不知道如何正确配置cmake以使用新安装的clang进行构建。

我通过Homebrew安装了clang:

brew install --HEAD llvm --with-clang

当我尝试使用新安装的编译器时,构建失败,因为它无法找到" cstdio"报头中。

那么我也克隆了&#3​​4; libcxx"来自github并更改了CMakeCache.txt中的设置:

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

以下是我在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

1 个答案:

答案 0 :(得分:3)

只要您使用--HEAD版本,通过Homebrew安装Clang应该可以正常工作。在构建Clang时,请确保在Release模式下构建;否则一些测试会触发Clang中的断言(很久以前就报告过这些错误)。我认为发布版本是Homebrew的默认版本,因此您无需采取任何措施。

然后,您还需要最新版本的libc ++。像你一样添加包含路径就可以了。但是,Hana需要使用-std = c ++ 1y而不是std = c ++ 11进行编译。 Hana已经将它需要的标志传递给编译器,所以如果按原样保留它们应该没问题,除了需要为libc ++修改的包含路径。

最后,您应该使用make -k代替make。即使出现错误,这也会指示make继续运行。问题是Clang主干仍然有几个与C ++ 14相关的错误导致它在某些测试中发生段错/断言/爆炸。特别是,core/example/is_a.cpp在过去一周左右间歇性地失败了。总而言之,在运行测试时,您应该期望3-4个断言。这很糟糕,但Clang的家伙已经意识到了这些问题。

TL; DR

尝试以下方法:

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

如果您使用Homebrew安装了Clang,path/to/clang/binary可能类似于/usr/local/opt/llvm/bin/clang++