cxref - Linux
Overview
cxref
is a powerful tool for cross-referencing symbols and identifiers in C and C++ source code. It generates comprehensive reports that map identifiers to their corresponding declarations, uses, and definitions, providing valuable insights into code structure and relationships.
Syntax
cxref [-options] [-f files] [-I paths]
Options/Flags
-a, --all
– Include all symbols (default: only defined symbols)-d, --declarations
– Only show declarations-f, --files
– Specify input files-I, --paths
: Include paths for preprocessor directives-r, --recursive
: Recursively search directories for source files-s, --summary
: Print a summary of cross-references-S, --source
: Include source lines in report-t, --types
: Include type information
Examples
List all symbols and their definitions
cxref -a my_code.c
Find all uses of a specific function
cxref -r my_project -d --files=my_function.c
Generate a summary report
cxref -s my_code.cpp -I/usr/include
Integration with other commands
Extract all function prototypes
cxref -d my_headers.h | grep "function"
Generate a call graph of a program
cxref -a my_program.c | dot -Tpng > callgraph.png
Common Issues
Symbols are not found
Ensure the input files and include paths are correct. Use -r
to search directories recursively.
Reports are too large or cluttered
Use -a
to filter results only to defined symbols. Use -S
to remove source lines from the report.
Related Commands
- ctags – Generate a tags file for quick symbol lookup
- grep – Search for specific patterns in text
- dot – Graph visualization tool from Graphviz