我使用自制软件在MacOS 10.13上安装了LLVM:
brew install --with-toolchain llvm
然后我导出了基于this guide的必需变量。
export PATH="/usr/local/opt/llvm/bin:$PATH"
export CC=/usr/local/opt/llvm/bin/clang
export CXX=/usr/local/opt/llvm/bin/clang++
export LLVM_OPTIONS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib "\
"-I/usr/local/opt/llvm/include -I/usr/local/opt/llvm/include/c++/v1/"
当运行clang-tidy时:
clang-tidy myheaderlib.h -- $LLVM_OPTIONS
我收到错误,所有错误都与标准文件有关:
/usr/local/opt/llvm/include/c++/v1/iosfwd:96:1: error: unknown type name '_LIBCPP_BEGIN_NAMESPACE_STD'
/usr/local/opt/llvm/include/c++/v1/iosfwd:100:1: error: unknown type name 'template'
...
可能是什么原因?
正如我发现的那样,问题是默认情况下clang-tidy将.h
文件视为C头。将其重命名为myheaderlib.hpp
解决了这个问题。我仍然喜欢听到如何正确配置clang-tidy,以便无论文件扩展名如何都可以指定语言。