使用 gcc 时在头文件中查找定义的好方法是什么?

发布于 2024-12-27 04:49:16 字数 167 浏览 0 评论 0原文

在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

緦唸λ蓇 2025-01-03 04:49:16

您可以运行 Doxygen 来生成基于 HTML 的源浏览器。这不需要使用 Doxygen 风格的文档来注释代码。它适用于多种语言,包括 C++JavaMarkdown.md 文件位于“相关页面” ”)。

这是从命令行配置和启动 Doxygen 的方法(在 Linux 上测试)...

## basic
echo -e "SOURCE_BROWSER=YES\n EXTRACT_ALL=YES\n RECURSIVE=YES\n" |doxygen -
xdg-open html/index.html

或者

## include diagrams and non-public content -- and launch browser immediately
echo -e "HAVE_DOT=YES\n CALL_GRAPH=YES\n CALLER_GRAPH=YES\n SOURCE_BROWSER=YES\n EXTRACT_ALL=YES\n EXTRACT_PRIVATE=YES\n EXTRACT_STATIC=YES\n RECURSIVE=YES\n SEPARATE_MEMBER_PAGES=YES\n GENERATE_LATEX=NO\n EXCLUDE_SYMLINKS=YES" |doxygen - && chromium-browser --new-window html/index.html

有一个名为 doxywizard 它允许您浏览可用于自定义生成的 HTML 的许多配置选项。或者,您可以运行 doxygen -g 来创建初始配置文件(其中包括详细提示)。

我建议使用以下非默认选项来生成源浏览器:

SOURCE_BROWSER=YES ## display source code
EXTRACT_ALL=YES ## display all items (not just "documented" ones)
RECURSIVE=YES ## include source found in subdirectories
SEPARATE_MEMBER_PAGES=YES ## optional -- each class member has its own page

一旦建立了主网页,您就可以浏览到感兴趣的源(或使用搜索功能)。来源与相关声明的可点击链接进行交叉引用。


我已经遇到过这个问题几次: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)...

## basic
echo -e "SOURCE_BROWSER=YES\n EXTRACT_ALL=YES\n RECURSIVE=YES\n" |doxygen -
xdg-open html/index.html

or

## include diagrams and non-public content -- and launch browser immediately
echo -e "HAVE_DOT=YES\n CALL_GRAPH=YES\n CALLER_GRAPH=YES\n SOURCE_BROWSER=YES\n EXTRACT_ALL=YES\n EXTRACT_PRIVATE=YES\n EXTRACT_STATIC=YES\n RECURSIVE=YES\n SEPARATE_MEMBER_PAGES=YES\n GENERATE_LATEX=NO\n EXCLUDE_SYMLINKS=YES" |doxygen - && chromium-browser --new-window html/index.html

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:

SOURCE_BROWSER=YES ## display source code
EXTRACT_ALL=YES ## display all items (not just "documented" ones)
RECURSIVE=YES ## include source found in subdirectories
SEPARATE_MEMBER_PAGES=YES ## optional -- each class member has its own page

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 also chmoding the permissions for better data security.

醉态萌生 2025-01-03 04:49:16

尝试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 to M-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.

三岁铭 2025-01-03 04:49:16

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.

北方。的韩爷 2025-01-03 04:49:16

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> 用于查找使用各种语言中的符号。在大多数编辑器中,集成度不如 ctagscscope 那样好,但可能更容易编写工具。您可以使用 mkid . 构建数据库,并使用 gid foolid foo 或类似的查找来查找符号。

我发现这三个工具提供了足够不同的功能,我经常使用这三个工具。 ctags 使得在 vim 中搜索源代码变得非常快,cscope 可以帮助找到调用者和被调用者,以及 gid(尤其是gid -s ...) 非常适合获取其他工具无法解决的复杂情况的一些提示。 (ctagscscope 都不理解 令牌粘贴很好,但是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 into ctags 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 using ctags -R . and look up definitions using your editor. (For example, vim -t foo will look up the foo tag in the ctags database and jump to that file and line.)

The GNU idutils package provides some nice utilities similar to ctags for finding uses of symbols in a variety of languages. Integration isn't as good in most editors as ctags or cscope but it might be easier for you to write tools. You build the database with mkid . and look up symbols with gid foo or lid foo or similar lookups.

I find the three tools provide different enough functionality that I use all three commonly. ctags makes hunting through source in vim extremely quick, cscope can help find callers and callees, and gid (especially gid -s ...) is good for just getting some hints on complex situations that the other tools don't just have solved. (Neither ctags nor cscope understands token pasting well, but gid -s lets me approximate a solution myself.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文