I've added everything to my $PATH
and I've tweaked my SConstruct
to set the appropriate environment variables, as per these answers [ 1 , 2 , 3 ]. Now when I run
scan-build --use-c++=`which clang++` scons
the build begins, and I can see the process forked by scons
is
/path/to/c++-analyzer ... -std=c++11 ...
The object file successfully builds, but then I get an error:
could not find clang line
This error occurs in c++-analyzer
when the forked process does not contain the string -cc1
. But if I check ps aux
, I clearly see
/path/to/clang -cc1 ...
How could the program build properly but the static analyzer fail like this?
For reference, if I manually run
scan-build clang++ <parameters from scons>
then the build succeeds and the report is generated!
I can also "cheat" by adding
env["ENV"]["PATH"] = os.environ["PATH"]
and then running
CXX="scan-build clang++" scons
I just can't run scan-build
on scons
itself with an unmodified SConstruct
.
The problem is that clang is not on the search path in the execution environment (Wayback Machine) . This explains why adding the line env["ENV"]["PATH"] = os.environ["PATH"]
solves the issue.
To run scan-build
on an unmodified SConstruct
you can put the clang executable ( clang++
and possibly clang
) on the search path used by the execution environment, eg by creating a symbolic link from /usr/bin/clang++
to your /path/to/clang++
on Linux.
I had the identical problem: the object file successfully builds, but then I got the error:
could not find clang line
The problem was that I was using a flag valid for gcc
but invalid for clang
.
touch empty.c
scan-build gcc -fdiagnostics-show-caret -c empty.c
scan-build: Using '/usr/bin/clang-8.exe' for static analysis
could not find clang line
...
scan-build --use-cc=clang gcc -fdiagnostics-show-caret -c empty.c
scan-build: Using '/usr/bin/clang-8.exe' for static analysis
clang-8: error: unknown argument: '-fdiagnostics-show-caret'
...
Removing the -fdiagnostics-show-caret
makes the problem go away:
scan-build gcc -c empty.c
scan-build: Using '/usr/bin/clang-8.exe' for static analysis
...
Also, to muddy the waters, clang
's name for this switch is -fcaret-diagnostics
, which gcc
will not accept.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.