Solution using -cc1
flag:
See what include paths the clang is receiving. The flag -v
is the key option. The quick way of using it is the following (as given by @Nishant) along with the sample include paths it prints,
$ clang -E -x c - -v < /dev/null
...
#include <...> search starts here:
/usr/local/include
/home/codeman/.itsoflife/local/packages-live/llvm-clang6/build/lib/clang/6.0.1/include
/usr/include/x86_64-linux-gnu
/usr/include
...
On my machine, the simple use of the following command works seamlessly,
$ clang --analyze -Xanalyzer -analyzer-checker=debug.DumpCFG main.c
however the following form fails, as you pointed,
$ clang -cc1 -analyze -analyzer-checker=debug.DumpCFG main.c
For this second command (with -cc1
) you can create an environment variable say MY_INCLUDES
with the necessary includes. Paste the code below (with necessary include paths as per your system) into ~/.bashrc
or ~/.zshrc
depending on if you are using bash
or zsh
. (don't forget to source ~/.bashrc
or source ~/.zshrc
)
export MY_INCLUDES="-I/usr/local/include -I/home/codeman/.itsoflife/local/packages-live/llvm-clang6/build/lib/clang/6.0.1/include -I/usr/include/x86_64-linux-gnu -I/usr/include"
Now on bash use,
$ clang -cc1 $MY_INCLUDES -analyze -analyzer-checker=debug.DumpCFG main.c
on zsh use,
$ clang -cc1 ${=MY_INCLUDES} -analyze -analyzer-checker=debug.DumpCFG main.c
Note the use of MY_INCLUDES
after -cc1
but before the main.c
file. Moreover, on zsh
one has to use the =
prefix with the env variable or else its considered a single string (for details see this answer).