我试图将Ale作为我的linter运行,这反过来又使用来链接我的代码。
$ clang-check FeatureManager.h
Error while trying to load a compilation database:
Could not auto-detect compilation database for file "FeatureManager.h"
No compilation database found in /home/babbleshack/ or any parent directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.
/home/babbleshack/FeatureManager.h:6:10: fatal error: 'unordered_map' file not found
#include <unordered_map>
^~~~~~~~~~~~~~~
1 error generated.
Error while processing /home/babbleshack/FeatureManager.h.而使用clang++编译只返回一个警告。
$ clang++ -std=c++11 -Wall FeatureManager.cxx FeatureManager.h
clang-5.0: warning: treating 'c-header' input as 'c++-header' when in C++ mode, this behavior is deprecated [-Wdeprecated]没有标志要clang-检查,允许我设置编译标志。
发布于 2017-12-04 00:25:31
花了一段时间才弄明白,但你可以
clang-check file.cxx -- -Wall -std=c++11 -x c++
或者如果您正在使用clang
clang-tidy file.cxx -- -Wall -std=c++11 -x c++
为了使两者都能使用ALE,我在vimrc中添加了以下内容
let g:ale_cpp_clangtidy_options = '-Wall -std=c++11 -x c++' let g:ale_cpp_clangcheck_options = '-- -Wall -std=c++11 -x c++'
如果您想让ALE也为C工作,那么您必须对g:ale_c_clangtidy_options和g:ale_c_clangcheck_options也这样做。
发布于 2020-02-22 12:05:48
我被类似的错误信息困扰了太久:
/my/project/src/util.h:4:10: error: 'string' file not found [clang-diagnostic-error]
#include <string>
^我看到其他questions表示我缺少了一些关键的包,但是所有的东西似乎都已经安装好了(而且我的代码构建得很好,只有clang-tidy正在变得不爽)。
传递-v显示我的.h文件的处理方式不同:
$ clang-tidy ... src/*.{h,cc} -- ... -v
...
clang-tool ... -main-file-name util.cc ... -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9 ... -x c++ ... /tmp/copy/src/util_test.cc
...
clang-tool ... -main-file-name util.h ... -x c-header /my/project/src/util.h
...正如克里斯所指出的,关键的区别是-x c-header标志,这是因为 file contains C, not C++,而这又意味着系统C++包含的内容没有被用来处理util.h。
但是-main-file-name标志在我看来也很奇怪,为什么头文件会成为主文件呢?在挖掘的同时,我还遇到了this short but insightful answer,头文件不应该被直接编译!使用src/*.cc而不是src/*.{h,cc}完全避免了这个问题,因为从一开始就不让Clang尝试自己处理.h!
不过,这确实带来了更多的皱纹。默认情况下不会报告这些头文件中的错误,因为它们不是您要求clang-tidy查看的文件。这就是"Use filter=.“显示来自所有非系统标头的错误的消息clang-tidy打印的地方。如果我传递-header-filter=src/.* (只包括我的src头,而不是包含在-I中的任何其他头文件),我就会在头文件中看到预期的错误。呼!
我不确定是一般地喜欢-x c++还是-header-filter=.*。-header-filter的一个缺点是,您必须调优筛选器正则表达式,而不仅仅是传递要检查的文件。但是另一方面,孤立地处理头文件本质上是浪费的工作(我希望在一个更大的项目中快速地累积起来)。
https://stackoverflow.com/questions/47583057
复制相似问题