CLANG-QUERY(1)

πŸ“¦
version 20.1.8 Β· 4 versions
, in ubuntu stonking

✨ NAME ✨

clang-query β€” okay bestie, this is literally the manual page for clang-query 20, and it sits in the User Commands corner of the manual (that's section 1, iykyk) πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

So the whole vibe of this thing, right, is this:

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

And then it's just options all the way down. Not me listing every single one β€” I am listing every single one 🫢

🌈 OPTIONS 🌈

πŸ’œ Generic Options:

  • --help β€” shows you the available options (and there's --help-hidden if you want more, bestie)
  • --help-list β€” shows you the list of available options (and --help-list-hidden for more, again)
  • --version β€” tells you the version of this program

πŸŽ€ clang-query options:

  • -c <command> β€” say which command to run
  • --extra-arg=<string> β€” an extra argument you want appended to the compiler command line
  • --extra-arg-before=<string> β€” an extra argument you want prepended to the compiler command line (front of the line energy, iconic)
  • -f <file> β€” read your commands from a file
  • -p <string> β€” the build path
  • --preload=<file> β€” preload commands from a file, then start interactive mode 🧚
  • --use-color β€” use colors in the detailed AST output. But if you don't set it, colors get used anyway when the terminal connected to standard output supports colors. So basically it's a "you didn't have to ask, but go off" situation ✨

πŸ“ the -p <build-path> of it all

-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 in it β€” and to get that file you use the -DCMAKE_EXPORT_COMPILE_COMMANDS=ON CMake option. And when you don't specify a build path at all, it goes looking for compile_commands.json up through every parent path of the first input file. If you want an example of setting up Clang Tooling on a source tree, see https://clang.llvm.org/docs/HowToSetupToolingForLLVM.html πŸ’–

πŸ¦‹ the <source0> ... of it all

<source0> ... is where you specify the paths of your source files. Those paths get looked up in the compile command database, and okay here's the part you actually need to hear:

  • If a file's path is absolute, it needs to point into CMake's source tree.
  • If a file's path is relative, then your current working directory needs to be in the CMake source tree, and the file has to be in a subdirectory of the current working directory.

Also, "./" prefixes in relative files get automatically removed β€” but the rest of a relative path has to be a suffix of a path in the compile command database. No cap, that's the rule 😭


And that's the whole page, angel. This was clang-query 20, dated September 2026 β€” go forth and query, you absolute main character, and remember: absolute paths point into the CMake source tree, relative paths need you standing in it πŸ‘‘

πŸ“¦ where this page comes from