CLANG-QUERY(1)
π NAME π
okay so bestie, this is the manual page for clang-query β yes, the whole CLANG-QUERY(1) situation, she's a User Commands girlie, and she's version 12. come sit with me, we're gonna get through this together π«Ά
β¨ DESCRIPTION β¨
here's how you actually call her:
USAGE: clang-query [options] <source0> [... <sourceN>]
and here's everything she takes, no skips, no cuts, we're doing all of it π
π Generic Options π
--helpβ shows you all the available options. and if that wasn't enough for you,--help-hiddengives you even more π--help-listβ prints the list of available options. and yeah, there's a--help-list-hiddenfor more, because of course there is π--versionβ tells you which version of the program you're running. classic, iconic, never misses.
π clang-query options π
-c=<command>β specify the 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 bestie, before, not after, they're different, don't mix them up π)-f=<file>β read commands from a file-p=<string>β the build path--preload=<file>β preload commands from a file and start interactive mode. it's giving multitasking πΈ--use-colorβ uses colors in detailed AST output. and here's the tea: if you don't set this, colors get used anyway if the terminal connected to standard output supports colors. so like, it's flexible. she's flexible.
π¦ about that build path π¦
so -p <build-path> is what you use to read a compile command database. yes, "database", very serious, very grown-up.
for example β and this is literally the example β it can be a CMake build directory that has a file called compile_commands.json in it. to get that output, use the -DCMAKE_EXPORT_COMPILE_COMMANDS=ON CMake option. π
and if you don't specify a build path? then she goes searching for compile_commands.json through all the parent paths of the first input file. she's resourceful like that.
if you want an example of setting up Clang Tooling on a source tree, go here:
https://clang.llvm.org/docs/HowToSetupToolingForLLVM.html
π about those source files π
<source0> ... you specify the paths of source files. and here's the part you actually need to remember:
- these paths get looked up in the compile command database
- if the path of a file is absolute, it needs to point into CMake's source tree
- 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
"./"prefixes in the relative files get automatically removed- but the rest of a relative path must be a suffix of a path in the compile command database
lowkey this is the part that trips everyone up so read it twice bestie, i'm not even joking π
and that's the whole vibe. clang-query 12, born February 2022, forever repping CLANG-QUERY(1). slay, periodt, go query some clang π
β¨
π¦ where this page comes from
- ubuntu jammy: clang-tools-12 1:12.0.1-19ubuntu3 Β· APACHE-2-LLVM-EXCEPTIONS
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms