5

I use g++ to compile my C++ project. When I try to use the clang static analyzer (scan-build) to check my code, I get an error:

>> scan-build g++ main.cpp
could not find clang line

How do I use the scan-build tool with g++?

Stuart Berg
  • 17,026
  • 12
  • 67
  • 99
  • 1
    From [the source](https://llvm.org/svn/llvm-project/cfe/trunk/tools/scan-build/ccc-analyzer), scan-build is looking for the line that contains `-cc1`. – chrisaycock Sep 18 '11 at 16:40
  • I'm not sure that you even should be able to. Should you not be using `llvm-g++`? – sehe Sep 18 '11 at 18:32

1 Answers1

2

It appears that scan-build is having trouble recognizing "g++" as the compiler command. It expects "clang" or "gcc". If you replace "g++" with "gcc -lstdc++" to build your project, the scan-build tool will work properly.

>> scan-build gcc -lstdc++ main.cpp
main.cpp:7:3: warning: Assigned value is garbage or undefined
  int y = x;
  ^       ~
1 warning generated.
scan-build: 1 bugs found.
scan-build: Run 'scan-view /var/folders/2l/2l6vhCnVFNad-O8ryd5YO++++TI/-Tmp-/scan-build-2011-09-18-2' to examine bug reports.
Stuart Berg
  • 17,026
  • 12
  • 67
  • 99