使用 gcc 时在头文件中查找定义的好方法是什么?
在使用 gcc 时,有人有推荐的方法在头文件中查找定义吗? 使用 MSVC 时,我只需右键单击并选择“转到定义”,这非常好。
我使用过 netbeans + gcc,它确实有代码帮助,包括定义的超链接,所以这是一种选择。但是,我想知道是否有任何其他 IDE 具有该功能,以及不使用 IDE 时的最佳方法。
Does anyone have a recommended way to find definitions in header files when using gcc?
When using MSVC, I can just right-click and select "Go to definition" which is really nice.
I have used netbeans + gcc, and it does have code assistance including hyperlinking to the definition, so that is one option. However, I would like to know if there are any other IDEs with that functionality and also the best way when not using an IDE.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以运行 Doxygen 来生成基于 HTML 的源浏览器。这不需要使用 Doxygen 风格的文档来注释代码。它适用于多种语言,包括 C++、Java 和 Markdown(
.md
文件位于“相关页面” ”)。这是从命令行配置和启动 Doxygen 的方法(在 Linux 上测试)...
或者
有一个名为 doxywizard 它允许您浏览可用于自定义生成的 HTML 的许多配置选项。或者,您可以运行 doxygen -g 来创建初始配置文件(其中包括详细提示)。
我建议使用以下非默认选项来生成源浏览器:
一旦建立了主网页,您就可以浏览到感兴趣的源(或使用搜索功能)。来源与相关声明的可点击链接进行交叉引用。
我已经遇到过这个问题几次:doxygen 可以创建非常长的文件名,而 Linux 加密的主目录的限制为 143字符。要解决此问题,您可能需要在主目录之外编写
html
文件夹。一个快速但肮脏的解决方案是将
html
链接到/tmp
或/dev/shm
中的文件夹 - 也可能是chmod< /code>ing 权限以获得更好的数据安全性。
You can run Doxygen to generate an HTML-based source browser. This does not require that the code be annotated with Doxygen-style documentation. It works for multiple language, including C++, Java, and Markdown (
.md
files go to "Related Pages").Here's a way of configuring and launching Doxygen from the command-line (tested on Linux)...
or
There is a companion program called doxywizard which lets you browse through the many configuration options available for customizing the generated HTML. Alternatively, you can run
doxygen -g
to create an initial configuration file (which includes detailed hints).I recommend the following non-default options to generate a source browser:
Once you have the main web page up, you can browse to the source of interest (or use the search feature). The source is cross-referenced with clickable links to relevant declarations.
I've run into this problem a few times: doxygen can create really long filenames and Linux encrypted home directory has a limit of 143 characters. To work around this, you may have to write the
html
folder outside of your home.A quick and dirty solution is to link
html
to a folder in/tmp
or/dev/shm
-- maybe alsochmod
ing the permissions for better data security.尝试CScope。与 Emacs 模块 xscope 一起,您可以告诉 Emacs Mx cscope-find-global-definition,它将跳转到定义符号的文件。 非常方便。
当然,Eclipse、KDevelop 或 Code::Blocks 等 IDE 也应该具有这样的功能。
Try CScope. Together with the Emacs module
xscope
you can tell Emacs toM-x cscope-find-global-definition
, which will jump to the file in which a symbol is defined. Very handy.Of course an IDE such as Eclipse or KDevelop or Code::Blocks should have such a feature, too.
Eclipse CDT 是独立于平台的,并且具有这样的功能(以及更多)。它索引了您项目中的所有内容(库+您自己的),因此您可以找到任何声明的定义(或者,我应该说,任何声明)。您可以将 Eclipse 视为面向 C++ 的精美文本编辑器,具有使用 makefile 启动 make(nmake.exe 或其他)的附加功能。
我使用 WinSDK 中的 Eclipse + MS cl.exe 编译器 - 它们一起工作就像魅力一样。我从 Eclipse 运行 nmake.exe,Eclipse 将 nmake.exe 控制台很好地重定向到特殊的 IDE 窗口。它还解析编译器的输出并自动突出显示有问题的行。
唯一需要做的就是在 Eclipse 中为 nmake.exe 设置环境变量。
Eclipse CDT is platform-independent and has such feature (plus more). It indexes all includes you have in your project (library + your own), so you can find definition of any declaration (or, should I say, any declaration). You can think of Eclipse as of fancy C++ oriented text editor with additional capabilities to launch make (nmake.exe or whatever) with your makefile.
I use Eclipse + MS cl.exe compilers from WinSDK - they work like charms together. I run nmake.exe from Eclipse, and Eclipse redirects nmake.exe console nicely into special IDE window. It also parses compiler's output and automatically highlights offending lines.
The only thing that one needs to do is to set up environment variables for nmake.exe from within Eclipse.
cscope
是我最喜欢的理解 C 代码的工具之一,但它可能翻译得不好进入 Windows 世界。丰富的
ctags
是查找多种语言定义的出色工具。大多数合理的编程编辑器都会提供一些接口来调用ctags
来获取定义信息。 (vim
,例如,允许您使用^]
查找符号的定义,并使用^T
弹出定义堆栈.) 您使用ctags -R .
构建数据库,并使用编辑器查找定义。 (例如,vim -t foo
将在ctags
数据库中查找foo
标记并跳转到该文件和行。)< a href="http://www.gnu.org/software/idutils/" rel="nofollow">GNU
idutils
软件包提供了一些类似于ctags< 的不错的实用程序< /code> 用于查找使用各种语言中的符号。在大多数编辑器中,集成度不如
ctags
或cscope
那样好,但您可能更容易编写工具。您可以使用mkid .
构建数据库,并使用gid foo
或lid foo
或类似的查找来查找符号。我发现这三个工具提供了足够不同的功能,我经常使用这三个工具。
ctags
使得在vim
中搜索源代码变得非常快,cscope
可以帮助找到调用者和被调用者,以及gid
(尤其是gid -s ...
) 非常适合获取其他工具无法解决的复杂情况的一些提示。 (ctags
和cscope
都不理解 令牌粘贴很好,但是gid -s
让我自己近似解决方案。)cscope
is one of my favorite tools for understanding C code but it may not translate well to the Windows world.exuberant
ctags
is an excellent tool for finding definitions in dozens of languages. Most reasonable programming editors provide some interface for calling intoctags
for definition information. (vim
, for example, allows you to use^]
to find a definition of a symbol and^T
to pop back up the definition stack.) You build a database usingctags -R .
and look up definitions using your editor. (For example,vim -t foo
will look up thefoo
tag in thectags
database and jump to that file and line.)The GNU
idutils
package provides some nice utilities similar toctags
for finding uses of symbols in a variety of languages. Integration isn't as good in most editors asctags
orcscope
but it might be easier for you to write tools. You build the database withmkid .
and look up symbols withgid foo
orlid foo
or similar lookups.I find the three tools provide different enough functionality that I use all three commonly.
ctags
makes hunting through source invim
extremely quick,cscope
can help find callers and callees, andgid
(especiallygid -s ...
) is good for just getting some hints on complex situations that the other tools don't just have solved. (Neitherctags
norcscope
understands token pasting well, butgid -s
lets me approximate a solution myself.)