CLANG-QUERY(1)

πŸ“¦
version 19.1.7 Β· 5 versions
, in debian bookworm, debian trixie

✨ NAME ✨

clang-query β€” the manual page for clang-query 19, bestie πŸ’…


🌸 DESCRIPTION 🌸

okay so here's the vibe. you run it like this:

USAGE: clang-query [options] <source0> [... <sourceN>]

and then you have OPTIONS, which we're gonna go through one by one, no skips, we're thorough here πŸ’–

πŸŽ€ Generic Options πŸŽ€

  • --help β€” shows you all the options that are available (and if you want the hidden ones too, use --help-hidden)
  • --help-list β€” shows you the full list of available options (and yeah, there's a --help-list-hidden for the hidden list too, iykyk)
  • --version β€” prints the version of this program, iconic

πŸ¦‹ clang-query options πŸ¦‹

  • -c <command> β€” tell it exactly which command to run
  • --extra-arg=<string> β€” an extra argument that gets appended to the compiler command line
  • --extra-arg-before=<string> β€” an extra argument that gets prepended to the compiler command line (yes, before, not after, they're different bestie)
  • -f <file> β€” read the commands from a file
  • -p <string> β€” the build path
  • --preload=<file> β€” preload commands from a file and then start interactive mode, so you get the best of both worlds
  • --use-color β€” uses colors in the detailed AST output. and if you don't set it, colors will still be used if the terminal connected to standard output supports colors. so basically it's giving "if you know you know" 🌈

πŸ’œ the build path situation πŸ’œ

-p <build-path> is what you use to read a compile command database.

for example, it can be a CMake build directory that has a file named compile_commands.json inside it (to get that output, use the -DCMAKE_EXPORT_COMPILE_COMMANDS=ON CMake option). and if you don't specify a build path at all, it'll attempt a search for compile_commands.json through all the parent paths of the first input file. see:

https://clang.llvm.org/docs/HowToSetupToolingForLLVM.html

for an example of setting up Clang Tooling on a source tree. go look, it's helpful fr fr πŸ“š

🌟 the source files 🌟

<source0> ... β€” these specify the paths of source files. and these paths are looked up in the compile command database.

here's the part where you have to pay attention, no cap: - if the path of a file is absolute, it needs to point into CMake's source tree. - if the path is relative, the current working directory needs to be in the CMake source tree, and the file must be in a subdirectory of the current working directory. - "./" prefixes in the relative files will be automatically removed, but the rest of a relative path must be a suffix of a path in the compile command database.

and that's the whole page, bestie 🫢 go query some clang, you got this πŸ‘‘

this was clang-query version 19, dated June 2025 β€” signing off, mwah πŸ’‹

πŸ“¦ where this page comes from