简体   繁体   English

在vim中使用syntastic启用cpp头文件检查

[英]enabling cpp header file checking with syntastic in vim

I just started using syntastic for vim, and I'm loving it so far, but I have one tiny issue. 我刚刚开始为vim使用syntastic,到目前为止我很喜欢它,但我有一个小问题。 If the file extension is not cpp, running ":SyntasticCheck" does absolutely nothing. 如果文件扩展名不是cpp,则运行“:SyntasticCheck”绝对没有任何作用。 This is a problem, as I would like to run syntastic on header files as well, with extensions such as ".h" or ".hpp". 这是一个问题,因为我想在头文件上运行syntastic,扩展名为“.h”或“.hpp”。 Can anyone help me out? 谁能帮我吗? I'm using 'gcc' as my cpp syntastic-checker, if that helps. 我正在使用'gcc'作为我的cpp syntastic-checker,如果有帮助的话。

Add the following to your vimrc 将以下内容添加到vimrc中

let g:syntastic_cpp_check_header = 1

this setting was found by reading the comment at the top of <syntastic>/syntax_checker/cpp/gcc.vim 通过阅读<syntastic>/syntax_checker/cpp/gcc.vim顶部的注释找到此设置

Basically, you need to add the path contains your header files such as let g:syntastic_c_include_dirs = ['../../include','../include','include'] and turn on the variable to check your header files let g:syntastic_c_check_header = 1 基本上,你需要添加包含你的头文件的路径,比如let g:syntastic_c_include_dirs = ['../../include','../include','include']let g:syntastic_c_include_dirs = ['../../include','../include','include']let g:syntastic_c_include_dirs = ['../../include','../include','include']然后打开变量检查你的标题文件let g:syntastic_c_check_header = 1

Moreover, you can also pass flags and options to compiler by let b:syntastic_c_cflags = '-I/usr/include/libsoup-2.4' and let g:syntastic_c_compiler_options = '-ansi -DMACRO_NAME' . 此外,您还可以通过let b:syntastic_c_cflags = '-I/usr/include/libsoup-2.4'将标志和选项传递给编译器,然后let g:syntastic_c_compiler_options = '-ansi -DMACRO_NAME'

It helps in many conditions ie when you have many macro definitions. 它有助于许多条件,即当您有许多宏定义时。

You can find more useful options in its official Github. 您可以在其官方Github中找到更多有用的选项。 C:gcc checker options C:gcc检查器选项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM