20

I'm working with a C++ project and trying to configure it to use syntastic. In my project I have a nested directory structure of header files (The actual nested structure is much worse, this is an example).

--libs    
    |---dir1
         |---foo1.h    
    |---dir2
         |---foo2.h
         |---foo3.h
         |---dir3
               |---foo4.h

I have included the lib files in my .vimrc file using:

let g:syntastic_cpp_include_dirs = [ 'libs/']

I assumed this would take all the header files recursively, but it doesn't. In the code, syntastic complains with the error 'no such file or directory found'.

When I explicitly change the variable to refer to a specific directory:

let g:syntastic_cpp_include_dirs = [ 'libs/dir2/dir3/']

it works.

My questions:

  1. How do you configure syntastic so that it includes header files of a set of directories recursively?
  2. How do you do this for multiple projects? Always editing the .vimrc as I switch the project I'm working on doesn't sound right. I believe there must be a better way.

EDIT:

I didn't mention that in my .vimrc, the following options are present for syntastic:

let g:syntastic_check_on_open=1
let g:syntastic_enable_signs=1
let g:syntastic_cpp_include_dirs = ['libs/dir2/dir3', 'libs/dir2 ]
let g:syntastic_cpp_check_header = 1
let g:syntastic_cpp_remove_include_errors = 1
4

2 回答 2

36

您可以在一个文件中包含要在项目根目录中搜索每个项目的头文件的所有目录.syntastic_cpp_config-I这样做的格式与向编译器提供指令的格式相同。

对于您的情况,这意味着:

  • .syntastic_cpp_config在下面创建一个文件sources(假设这是您的代码所在的位置,并且sources在目录层次结构中处于与 相同的深度级别libs)。
  • 将以下几行放入其中:

    -Ilibs/dir1

    -Ilibs/dir2

    -Ilibs/dir2/dir3

  • 请注意,标志是每行 1 个。

  • 这样您就不必在.vimrc.

您可以有一个不同的文件来保存每个项目的自定义配置,由.vimrc全局变量指定g:syntastic_cpp_config_file,例如

let g:syntastic_cpp_config_file = '.my_custom_include_file_for_syntastic'

Syntastic 将检查每个源目录并向上检查,直到找到该文件,然后将其用于生成其输出。

请参阅Syntastic wiki 页面旧链接了解更多详细信息。

于 2013-10-02T18:14:48.800 回答
0

我有同样的问题,但运气不佳。但是,我发现如果我使用引号样式标题包含,语法将适当地检查文件夹并且不会发出警告。例如,如果您正在处理 foo2.cpp,

#include "dir3/foo4.h"
#include "../dir1/foo1.h"

保存括号包括标准库和任何您想硬编码到 vim 中的库。

于 2013-05-30T03:08:27.067 回答