【发布时间】:2020-02-16 09:16:23
【问题描述】:
今天我从源代码构建了 clang-tidy,我使用 clang++ 构建了它。构建完成后,我创建了一个指向可执行文件的符号链接,如下所示:
ln -s /path/to/build/bin/clang-tidy /usr/local/bin/clang-tidy
然后我尝试在简单项目(包含打印 helloworld 代码的单个 .cpp 文件)上使用 clang-tidy 和 cmake。这是我的 cmake 文件的样子:
project(Test)
cmake_minimum_required(VERSION 3.12.0 FATAL_ERROR)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
set(CMAKE_CXX_STANDARD 17)
set(CXX_STANDARD_REQUIRED)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_CLANG_TIDY
clang-tidy;
-checks=*;)
add_executable(Test
helloworld.cpp)
我在某处读到,cmake-tidy 仅适用于 Unix Makefiles 和 Ninja 生成器(或可能其他一些)。我通常使用 xcode 生成器,但我对这两个不太熟悉,所以我并不真正关心其他人。我尝试使用 Unix Makefiles 和 Ninja 生成和构建项目,但两者都出现此错误:
/Users/xxxxxxx/Dev/VSCodePlayground/helloworld.cpp:2:10: error: 'string' file not found [clang-diagnostic-error]
我找到了一些信息,这可能是因为 clang 找不到 libc++/stdlib 头文件。因此,我尝试使用 -v 参数进行建议编译(成功且没有错误),并在包含目录中获得了此输出:
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
如果我理解问题是 clang-tidy 不知道 libc++ 标头的位置,而 clang 知道,对吗?但是我应该如何解决这个问题以及导致这个问题的原因?
【问题讨论】:
-
我认为这不是你的问题,因为你在
.cpp文件中看到了这个错误,但我在.h文件和@987654321 中遇到了同样的问题@;也许它会帮助你。
标签: macos clang clang-tidy