递归包括头文件以进行合成 [英] Including header files recursively for syntastic

查看:83
本文介绍了递归包括头文件以进行合成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个C ++项目,并试图将其配置为使用syntastic.在我的项目中,我有一个头文件的嵌套目录结构(实际的嵌套结构更糟,这是一个示例).

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

我已使用以下方式将lib文件包含在我的.vimrc文件中:

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

让g:syntastic_cpp_include_dirs = ['libs/']

let g:syntastic_cpp_include_dirs = [ 'libs/']

我假设这将递归地获取所有头文件,但事实并非如此.在代码中,syntastic抱怨错误找不到此类文件或目录".

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:

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

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

有效.

我的问题:

  1. 如何配置syntastic,以使其递归地包含一组目录的头文件?
  2. 您如何针对多个项目执行此操作?切换正在处理的项目时,总是编辑.vimrc听起来不正确.我相信必须有更好的方法.

我没有在我的.vimrc文件中提到过,以下是用于合成的选项:

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

推荐答案

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

You can include all the directories to be searched for header files per project in the project root directory in a file .syntastic_cpp_config. The format for doing so would the same as providing the -I directives to the compiler.

对于您而言,这意味着:

For your case it means:

  • sources 下创建文件 .syntastic_cpp_config (假设您的代码所在,而 sources 在目录层次结构中位于同一深度级别作为 libs ).
  • 在其中添加以下几行:

  • Create a file .syntastic_cpp_config under sources (assuming that's where your code is and sources is at a same depth level in the directory hierarchy as libs).
  • Put the following lines in it:

-Ilibs/dir1

-Ilibs/dir2

-Ilibs/dir2/dir3

请注意,标志为每行1个.

Note the the flags are 1 per line.

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

You can have a different file to hold this custom configuration per project, specified by the .vimrc global variable g:syntastic_cpp_config_file, eg

let g:syntastic_cpp_config_file = '.my_custom_include_file_for_syntastic'

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

Syntastic will check each source directory and upwards until it finds this file and then use it for producing its output.

请参见语法Wiki页面旧链接以获取更多详细信息.

See the Syntastic wiki page, Old link for more details.

这篇关于递归包括头文件以进行合成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆