如何调整 Eclipse 的 C++ 索引器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/58554/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to tweak Eclipse's C++ Indexer?
提问by Carl Seleborg
I'm using Eclipse as my IDE for a C++ project, and I would love for it to tell me where a given symbol is defined and what the parameters are for a function.
我正在使用 Eclipse 作为 C++ 项目的 IDE,我希望它告诉我给定符号的定义位置以及函数的参数是什么。
However, there's a catch: I also use Lazy C++, a tool that takes a single source file and generates the .h and the .cpp files. Those .lzz files look like headers, but this tool supports some very mild syntactic benefits, like combining nested namespaces into a qualified name. Additionally, it has some special tags to tell the tool specifically where to put what (in header or in source file).
但是,有一个问题:我也使用Lazy C++,这是一种采用单个源文件并生成 .h 和 .cpp 文件的工具。那些 .lzz 文件看起来像标题,但该工具支持一些非常温和的语法优势,例如将嵌套命名空间组合成限定名称。此外,它有一些特殊的标签来告诉工具具体放什么(在头文件或源文件中)。
So my typical SourceFile.lzz looks like this:
所以我典型的 SourceFile.lzz 看起来像这样:
$hdr
#include <iosfwd>
#include "ProjectA/BaseClass.h"
$end
$src
#include <iostream>
#include "ProjectB/OtherClass.h"
$end
// Forward declarations
namespace BigScope::ProjectB
{
class OtherClass;
}
namespace BigScope::ProjectA
{
class MyClass : public ProjectA::BaseClass
{
void SomeMethod(const ProjectB::OtherClass& Foo) { }
}
}
As you see, it's still recognizable C++, but with a few extras.
如您所见,它仍然是可识别的 C++,但有一些附加功能。
For some reason, CDT's indexer does not seem to want to index anything, and I don't know what's wrong. In the Indexer View, it shows me an empty tree, but tells me that it has some 15000 symbols and more stuff, none of which I can seem to access.
不知为何,CDT的索引器似乎不想索引任何东西,不知道哪里出了问题。在索引器视图中,它向我展示了一棵空树,但告诉我它有大约 15000 个符号和更多的东西,我似乎无法访问这些。
So here's my question: how can I make the Indexer output some more information about what it's doing and why it fails when it does so, and can I tweak it more than with just the GUI-accessible options?
所以这是我的问题:我怎样才能让索引器输出更多关于它正在做什么以及它为什么会失败的信息,我是否可以调整它而不仅仅是使用 GUI 可访问的选项?
Thanks,
谢谢,
Carl
卡尔
回答by Mike McQuaid
I'd imagine its one of:
我想它是其中之一:
Eclipse doesn't want to display non-C++ resources in the tree (I've had problems with this)
You don't have "Preferences > C/C++ > Indexer > Index All Files" enabled.
You want to use the "Full C/C++ Indexer" rather than the "Fast C/C++ Indexer"
Eclipse 不想在树中显示非 C++ 资源(我遇到了这个问题)
您没有启用“首选项 > C/C++ > 索引器 > 索引所有文件”。
您想使用“Full C/C++ Indexer”而不是“Fast C/C++ Indexer”
回答by Mike Kucera
The CDT parser/indexer won't recognize weird extensions like that. The only thing you can do is to define macros on the Paths and Symbols property page to trick the parser. Try creating macros for $hdr
, $end
and $src
that have empty bodies. That way the preprocessor will remove them and the parser won't choke on them.
CDT 解析器/索引器不会识别这样的奇怪扩展。您唯一能做的就是在 Paths and Symbols 属性页上定义宏来欺骗解析器。尝试为$hdr
、$end
和$src
具有空的主体创建宏。这样预处理器将删除它们并且解析器不会阻塞它们。