12

I have installed scan-build/clang version 2.9 on Ubuntu desktop. I build my C++ source code there using make . As it said scan-build would analyze a project which is built using make if you give

scan-build make 

to

but after the make i see a message

scan-build: Removing '/tmp/scan-build-2013-10-16-1' because it contains no reports.

Also tried

scan-build --use-c++=/use/bin/clang++ make

Q1 - What am i doing wrong/missing here. How to use scan-build to analyze all source files.

Q2 - Is there any option to use clang++ --analyze myfile.cpp to analyze single source file. But it gives an error about a header file included not found 'fatal' error' my.h

what is the option to clang analyze to point it to the folder having header files.

1 Answer 1

7
+50

As for Q2, you should be able to use:

scan-build clang++ -c myfile.cpp

or what you suggested:

clang++ --analyze myfile.cpp

but you need to make sure that the compiler knows about all the includes and libraries (you should be able to successfully compile myfile.cpp to an object file without analysis). That includes especially the -I directories.

There is also the -o option to scan-build, which specifies the target directory for HTML report files. Subdirectories will be created as needed to represent separate "runs" of the analyzer. If this option is not specified, a directory is created in /tmp to store the reports, as you already know.

Another useful option would be -v (verbose), which should print any errors that the analyzer might run into.

Last but not least, you should use the analysis with debug builds where the optimization is disabled, but more importantly where the symbols are not stripped.

Not sure if it helps, let me know ...

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks -I was the option i missed. It helped.
I must mention though that "scan-build clang++ -c myfile.cpp" does not static analyze the file, but compile, build and links it.
If a cpp file includes headers, it gives "file not found" error. Is there an easy way to add the header files?
@ErayTuncer eeh, you mean using -I?
@ErayTuncer It specifies the path to search include files. So rather than files, you should specify a folder in which your headers are. In fact, in case you are able to compile it with clang or g++, the -I option there is just the same.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.