CLANG-QUERY(1)

πŸ“¦
version 17.0.6 Β· 4 versions
, in debian trixie, ubuntu questing

πŸ’… NAME πŸ’…

clang-query β€” it's the manual page for clang-query 17, bestie, and she's a whole vibe. It's in the User Commands section of the manual, so like, she's a grown-up command. Come sit, I'll walk you through it 🫢


✨ DESCRIPTION ✨

Okay so here's the whole thing, usage first, no cap:

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

Then it goes straight into the options. Let's goooo πŸ’–

🌸 OPTIONS 🌸

πŸŽ€ Generic Options πŸŽ€

  • --help β€” shows you all the available options. And if you want the secret menu version, there's --help-hidden for more πŸ‘€
  • --help-list β€” shows you a whole list of the available options. Want the hidden list too? That's --help-list-hidden for more, periodt.
  • --version β€” tells you what version of this program you're running. Iconic.

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

  • -c <command> β€” specify the command to run. Just say what you wanna do, babe.
  • --extra-arg=<string> β€” an additional argument to append to the compiler command line. It goes at the end, at the back of the line, last one in πŸ’…
  • --extra-arg-before=<string> β€” an additional argument to prepend to the compiler command line. Front of the line, main character energy, she cuts everybody ✨
  • -f <file> β€” read commands from a file. Very "here's my list, I'm not saying it out loud" of you.
  • -p <string> β€” build path.
  • --preload=<file> β€” preload commands from a file and start interactive mode. Like, you show up already knowing things but you're still here to chat 🫢
  • --use-color β€” use colors in detailed AST output. And listen, if it's not set, colors will be used if the terminal connected to standard output supports colors. So either way you might get rainbows 🌈 β€” she decides based on your terminal's whole situation.

πŸ’œ So what even is -p <build-path>? πŸ’œ

-p <build-path> is used to read a compile command database. That's the whole point of her.

For example, it can be a CMake build directory in which a file named compile_commands.json exists. To get that output, use the -DCMAKE_EXPORT_COMPILE_COMMANDS=ON CMake option. Yep, exactly like that, character for character, don't improvise.

And when no build path is specified? She goes on a lil scavenger hunt: a search for compile_commands.json will be attempted through all parent paths of the first input file. She's thorough like that πŸ’…

See: https://clang.llvm.org/docs/HowToSetupToolingForLLVM.html for an example of setting up Clang Tooling on a source tree. Very much iykyk.


🧚 The source files, aka <source0> ... <sourceN> 🧚

These specify the paths of source files. And here's where it gets specific, so pay attention bestie:

  • These paths are looked up in the compile command database. That's the rules.
  • If the path of a file is absolute</>, it needs to point into CMake's source tree. No exceptions, she's not flexible about this.
  • If the path is relative</>, then 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.
  • The "./" 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. So like, the ending has to match something in there. That's just how it is πŸŽ€
Lowkey this is the part people get wrong and then get mad at the tool. It's not the tool, bestie. Read the path rules again πŸ™ˆ

🌟 Sign-off 🌟

That's the whole page, gorgeous. This is clang-query 17, dated June 2025, and it lives in the CLANG-QUERY(1) manual section. Go forth and query, queen πŸ‘‘πŸ’–βœ¨

πŸ“¦ where this page comes from