14

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.

Community
  • 1
  • 1
chrisaycock
  • 36,470
  • 14
  • 88
  • 125
  • Your question is answered in the first linked answer: "SCons normally cleans out the environment before running a build (this is a feature)." – Industrial-antidepressant Mar 13 '13 at 21:05
  • @Industrial-antidepressant I already use the environment variables that Greg suggests. I can *build* via Clang and SCons just fine; I can't run the *static analyzer*. – chrisaycock Mar 13 '13 at 21:12
  • Hmm, try with scan-build --use-analyzer=/path/to/clang – Industrial-antidepressant Mar 13 '13 at 21:38
  • @Industrial-antidepressant `--use-analyzer` isn't a recognized option for `scan-build`. – chrisaycock Mar 15 '13 at 21:05
  • that option was added to clang in Fri Aug 24 23:08:08 2012 with commit msg "Rework how scan-build picks the version of clang to use for static analysis", and released with clang 3.2 – Industrial-antidepressant Mar 16 '13 at 15:00
  • @Industrial-antidepressant I finally got Clang 3.2 and tried the `--use-analyzer`. I still get the same error. Thanks anyway though. – chrisaycock Mar 26 '13 at 14:42
  • Intresting... I manually compiled and installed the clang, and I have the same error message, but I did not used scons but a similar one, called waf. I have to use the --use-analyzer=/path/to/clang and that path must contain the binary itself, not just the path. – Industrial-antidepressant Mar 26 '13 at 14:49

2 Answers2

5

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, e.g. by creating a symbolic link from /usr/bin/clang++ to your /path/to/clang++ on Linux.

Joseph Quinsey
  • 9,553
  • 10
  • 54
  • 77
vitaut
  • 49,672
  • 25
  • 199
  • 336
1

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.

Joseph Quinsey
  • 9,553
  • 10
  • 54
  • 77
  • **Edit:** I should note that `scan-build -v -v -v` here showed only a minimal amount of information, and it was not helpful. – Joseph Quinsey Jun 03 '21 at 13:18