LinuxCommandLibrary

castxml

generate XML descriptions of C/C++ declarations

TLDR

Generate XML from C++ header

$ castxml --castxml-output=1 [header.hpp] -o [output.xml]
copy
Generate gccxml-compatible output
$ castxml --castxml-gccxml [header.hpp] -o [output.xml]
copy
Configure for GNU compiler
$ castxml --castxml-cc-gnu [g++] [header.hpp] -o [output.xml]
copy
Start traversal at specific declaration
$ castxml --castxml-start [ClassName] [header.hpp] -o [output.xml]
copy
Include path and defines
$ castxml -I[/include/path] -D[MACRO] [header.hpp] -o [output.xml]
copy

SYNOPSIS

castxml [options] inputfile_

DESCRIPTION

castxml creates an XML representation of C and C++ declarations from source files. It uses the Clang compiler frontend to parse C-family source code and produces a structured XML output describing types, functions, classes, and other declarations.
The tool is commonly used as a foundation for generating language bindings, enabling projects like pygccxml to automatically create Python wrappers for C++ libraries. It also serves as a code analysis backend where machine-readable representations of header files are needed.
CastXML was created as a replacement for the deprecated GCC-XML tool, providing a modern Clang-based alternative with compatible output formats for backward compatibility.

PARAMETERS

--castxml-output=version

Generate castxml-format output (version must be '1')
--castxml-gccxml
Generate gccxml-compatible output format
--castxml-cc-gnu compiler
Configure preprocessor/target for GNU compiler
--castxml-cc-msvc compiler
Configure preprocessor/target for MSVC compiler
--castxml-cc-gnu-c compiler
Configure for GNU C compiler
--castxml-cc-msvc-c compiler
Configure for MSVC C compiler
--castxml-start name
Start AST traversal at named declaration
-o file
Output file path
-I path
Add include search path
-D macro
Define preprocessor macro
-std=standard
C++ standard (c++11, c++14, c++17, etc.)

USE CASES

Language bindings

Generate bindings for Python, Rust, etc.
Code analysis
Parse and analyze C++ codebases
Documentation
Extract API information

CAVEATS

Output format depends on selected option. GCCXML format provided for legacy compatibility. Use with pygccxml for Python-based analysis.

SEE ALSO

clang(1), g++(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community