可以让 ctags 遵循 #include 指令吗? [英] Can ctags be made to follow #include directives?

查看:28
本文介绍了可以让 ctags 遵循 #include 指令吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的 Makefile 中创建一个目标,以使用 ctags 自动创建一个 tags 文件.

I am trying to create a target in my Makefile to automatically create a tags file using ctags.

我有一个源文件列表(.cpp 文件),但我没有所有头文件的列表(我使用 g++ -MM 创建头依赖项列表).

I have a list of source files (.cpp files) but I don't have a list of all the header files (I use g++ -MM to create the list of header dependencies).

我本以为 ctags 会在生成标签时遵循 .cpp 文件中的任何 #include 指令,但似乎我的假设是错误的.

I would have assumed that ctags would follow any #include directives in the .cpp files when generating the tags, but it seems my assumption is wrong.

如果我像这样创建一个简单的标签文件:

If I create a simple tags file like this:

ctags  --fields=+iaS --extra=+q myClass.cpp

然后进入vim并输入一个对象的名称,后跟一个'.'我收到错误找不到模式".

and then go into vim and type in the name of an object followed by a '.' I get the error "Pattern not found".

但是,如果我像这样编译标签文件:

However, if I compile the tags file like this:

ctags  --fields=+iaS --extra=+q myClass.cpp myClass.h

在 vim 中做同样的事情,我得到一个可爱的自动完成的成员变量/函数列表.

and do the same thing in vim I get a lovely auto-completed list of member variables/functions.

我的myClass.cpp"文件中的第一行是

The first line in my 'myClass.cpp' file is

#include "myClass.h"

那么为什么 ctags 不使用它来解析头文件呢?

So why doesn't ctags use that to parse the header file too?

推荐答案

不.不幸/幸运.

遵循您自己的包含不会有太多问题.问题始于

There wouldn't be too many problems following your own includes. The problem starts with

  • 条件编译
  • 外部(系统)库.

幸运的是,你自己的图书馆的问题很容易通过做类似的事情来解决

Fortunately, the problem for your own libraries is easily solved by doing something like

ctags *.h *.cpp
ctags -R src/

你可以用 cppctags 一起破解一些东西.它不会方便地工作.一个有趣的方法是修补 ctags 以遵循 cpp 输出中的 #line 编译指示,从而将所有标签与其各自的来源相关联.

You could hack something together with cpp and then ctags. It would not work conveniently. A half-interesting approach would be to patch ctags to follow the #line pragma's in cpp's output and hence relate all tags to their respective sources.

但是,对于任何预处理器符号/定义,这种方法不会像您期望的那样工作(宏已被扩展,因此您将无法通过 ctags 找到宏).

However, that approach would not work as you'd expect for any preprocessor symbols/defines (macros have been expanded, so you wouldn't be able to find a macro by ctags).

解决此问题的常用方法是为您的外部库生成标准"标签文件,并且

The usual way to resolve this, is to generate a 'standard' tags file for your external libraries, and

:se tags+=/home/me/libs/tags.stdc++
:se tags+=/home/me/libs/tags.libsox

等等.一些库有关于如何制作有用的标签文件以用于他们的库(或假设特定文件夹布局的预构建标签文件)的教程

etc. Several libraries have tutorials on how to make a useful tags file for use with their libraries (or prebuilt tags files assuming a certain folder layout)

这篇关于可以让 ctags 遵循 #include 指令吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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