在没有IDE的情况下如何查找声明/定义? [英] How do I find declarations/definitions without an IDE?

查看:104
本文介绍了在没有IDE的情况下如何查找声明/定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几年来我一直在使用Eclipse IDE.在C语言中进行编程时,我习惯按住Ctrl键并单击某个符号,然后Eclipse将我带到该符号声明的文件和行中.

I've been using the Eclipse IDE for a few years now. When programming in C I'm used to Ctrl+Click on a symbol and Eclipse takes me to the file and line of the symbol's declaration.

如果没有IDE,我该如何实现?我正在使用gcc编译具有数百个头文件的大型FOSS项目.查看C文件,可以看到我想了解更多的功能.查找声明该功能的头文件是一项繁琐且手动的任务.更不用说手动解释宏了...

Without an IDE, how do I achieve this? I'm using gcc to compile a massive FOSS project with hundreds of header files. Looking though the C files, I see functions that I would like to know more about. Finding the header file that declares said function is a tedious and manual task. Not to mention manual interpretation of macros...

GCC编译项目并知道声明是什么以及在哪里.对于给定的编译,是否可以为所有符号声明以及它们的文件名和位置生成人类可读的索引?

GCC compiles the project and knows what the declarations are and where. Is it possible to generate a human readable index of all symbol declarations along with their filename and position for a given compilation?

推荐答案

听起来像您在寻找-aux-info标志;它将把在转换单元中声明或定义的所有函数的列表(包括头文件中的函数)写入指定的输出文件.

Sounds like you're looking for the -aux-info flag; it will write a list of all functions declared or defined in a translation unit (including those in header files) to a specified output file.

这是我为另一个SO问题(不记得它是为了什么)写的一段愚蠢的代码:

Here's a dumb piece of code I wrote for another SO question (don't remember what it was for):

#include <stdio.h>

int main( int argc, const char *argv[] )
{
  const unsigned long long lim = 2000000;
  unsigned long long nums2lim[lim];

  printf( "%zu\n", sizeof nums2lim );
  return 0;
}

使用

gcc -o test -std=c99 -pedantic -Wall -Werror -aux-info=test.aux test.c

test.aux中产生此输出:

/* compiled from: . */
/* /usr/include/libio.h:413:NC */ extern int __underflow (_IO_FILE *);
/* /usr/include/libio.h:414:NC */ extern int __uflow (_IO_FILE *);
/* /usr/include/libio.h:415:NC */ extern int __overflow (_IO_FILE *, int);
/* /usr/include/libio.h:416:NC */ extern wint_t __wunderflow (_IO_FILE *);
/* /usr/include/libio.h:417:NC */ extern wint_t __wuflow (_IO_FILE *);
/* /usr/include/libio.h:418:NC */ extern wint_t __woverflow (_IO_FILE *, wint_t);
/* /usr/include/libio.h:451:NC */ extern int _IO_getc (_IO_FILE *);
/* /usr/include/libio.h:452:NC */ extern int _IO_putc (int, _IO_FILE *);
/* /usr/include/libio.h:453:NC */ extern int _IO_feof (_IO_FILE *);
/* /usr/include/libio.h:454:NC */ extern int _IO_ferror (_IO_FILE *);
/* /usr/include/libio.h:456:NC */ extern int _IO_peekc_locked (_IO_FILE *);
/* /usr/include/libio.h:462:NC */ extern void _IO_flockfile (_IO_FILE *);
/* /usr/include/libio.h:463:NC */ extern void _IO_funlockfile (_IO_FILE *);
/* /usr/include/libio.h:464:NC */ extern int _IO_ftrylockfile (_IO_FILE *);
/* /usr/include/libio.h:482:NC */ extern int _IO_vfscanf (_IO_FILE *, const char *, __va_list_tag *, int *);
/* /usr/include/libio.h:484:NC */ extern int _IO_vfprintf (_IO_FILE *, const char *, __va_list_tag *);
/* /usr/include/libio.h:485:NC */ extern __ssize_t _IO_padn (_IO_FILE *, int, __ssize_t);
/* /usr/include/libio.h:486:NC */ extern size_t _IO_sgetn (_IO_FILE *, void *, size_t);
/* /usr/include/libio.h:488:NC */ extern __off64_t _IO_seekoff (_IO_FILE *, __off64_t, int, int);
/* /usr/include/libio.h:489:NC */ extern __off64_t _IO_seekpos (_IO_FILE *, __off64_t, int);
/* /usr/include/libio.h:491:NC */ extern void _IO_free_backup_area (_IO_FILE *);
/* /usr/include/stdio.h:154:NC */ extern int remove (const char *);
/* /usr/include/stdio.h:156:NC */ extern int rename (const char *, const char *);
/* /usr/include/stdio.h:171:NC */ extern FILE *tmpfile (void);
/* /usr/include/stdio.h:185:NC */ extern char *tmpnam (char *);
/* /usr/include/stdio.h:213:NC */ extern int fclose (FILE *);
/* /usr/include/stdio.h:218:NC */ extern int fflush (FILE *);
/* /usr/include/stdio.h:249:NC */ extern FILE *fopen (const char *, const char *);
/* /usr/include/stdio.h:256:NC */ extern FILE *freopen (const char *, const char *, FILE *);
/* /usr/include/stdio.h:309:NC */ extern void setbuf (FILE *, char *);
/* /usr/include/stdio.h:314:NC */ extern int setvbuf (FILE *, char *, int, size_t);
/* /usr/include/stdio.h:334:NC */ extern int fprintf (FILE *, const char *, ...);
/* /usr/include/stdio.h:339:NC */ extern int printf (const char *, ...);
/* /usr/include/stdio.h:342:NC */ extern int sprintf (char *, const char *, ...);
/* /usr/include/stdio.h:349:NC */ extern int vfprintf (FILE *, const char *, __va_list_tag *);
/* /usr/include/stdio.h:354:NC */ extern int vprintf (const char *, __va_list_tag *);
/* /usr/include/stdio.h:357:NC */ extern int vsprintf (char *, const char *, __va_list_tag *);
/* /usr/include/stdio.h:365:NC */ extern int snprintf (char *, size_t, const char *, ...);
/* /usr/include/stdio.h:369:NC */ extern int vsnprintf (char *, size_t, const char *, __va_list_tag *);
/* /usr/include/stdio.h:406:NC */ extern int fscanf (FILE *, const char *, ...);
/* /usr/include/stdio.h:411:NC */ extern int scanf (const char *, ...);
/* /usr/include/stdio.h:414:NC */ extern int sscanf (const char *, const char *, ...);
/* /usr/include/stdio.h:425:NC */ extern int vfscanf (FILE *, const char *, __va_list_tag *);
/* /usr/include/stdio.h:432:NC */ extern int vscanf (const char *, __va_list_tag *);
/* /usr/include/stdio.h:437:NC */ extern int vsscanf (const char *, const char *, __va_list_tag *);
/* /usr/include/stdio.h:447:NC */ extern int fgetc (FILE *);
/* /usr/include/stdio.h:448:NC */ extern int getc (FILE *);
/* /usr/include/stdio.h:454:NC */ extern int getchar (void);
/* /usr/include/stdio.h:489:NC */ extern int fputc (int, FILE *);
/* /usr/include/stdio.h:490:NC */ extern int putc (int, FILE *);
/* /usr/include/stdio.h:496:NC */ extern int putchar (int);
/* /usr/include/stdio.h:539:NC */ extern char *fgets (char *, int, FILE *);
/* /usr/include/stdio.h:546:NC */ extern char *gets (char *);
/* /usr/include/stdio.h:596:NC */ extern int fputs (const char *, FILE *);
/* /usr/include/stdio.h:602:NC */ extern int puts (const char *);
/* /usr/include/stdio.h:609:NC */ extern int ungetc (int, FILE *);
/* /usr/include/stdio.h:617:NC */ extern size_t fread (void *, size_t, size_t, FILE *);
/* /usr/include/stdio.h:623:NC */ extern size_t fwrite (const void *, size_t, size_t, FILE *);
/* /usr/include/stdio.h:656:NC */ extern int fseek (FILE *, long int, int);
/* /usr/include/stdio.h:661:NC */ extern long int ftell (FILE *);
/* /usr/include/stdio.h:666:NC */ extern void rewind (FILE *);
/* /usr/include/stdio.h:705:NC */ extern int fgetpos (FILE *, fpos_t *);
/* /usr/include/stdio.h:710:NC */ extern int fsetpos (FILE *, const fpos_t *);
/* /usr/include/stdio.h:733:NC */ extern void clearerr (FILE *);
/* /usr/include/stdio.h:735:NC */ extern int feof (FILE *);
/* /usr/include/stdio.h:737:NC */ extern int ferror (FILE *);
/* /usr/include/stdio.h:753:NC */ extern void perror (const char *);
/* test.c:4:NF */ extern int main (int argc, const char **argv); /* (argc, argv) int argc; const char **argv; */

不过,该标志仅适用于C代码-它不会为C ++提供任何帮助.

This flag only works for C code, though - it won't give you anything for C++.

这篇关于在没有IDE的情况下如何查找声明/定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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