I do not have administrative rights on a linux server (openSuse Linux) I am working on right now. So installing anything is not an option or at least an easy option. But I wanted to run cppcheck on my new C++11 source code. Here is what I found to achieve that:

Download the tarball from the below link

https://sourceforge.net/projects/cppcheck/

Create a home for the cppcheck source code and move the tarball into that folder:

[code language=”bash”]
mkdir cpp_check
mv cppcheck-1.85.tar.bz2 cpp_check/.
cd cpp_check
[/code]

Extract the tarball

[code language=”bash”]
tar xvjf cppcheck-1.85.tar.bz2
[/code]

Compile the source code

[code language=”bash”]
g++ -o cppcheck -std=c++11 -Iexternals/simplecpp -Iexternals/tinyxml -Ilib cli/*.cpp lib/*.cpp externals/simplecpp/simplecpp.cpp externals/tinyxml/*.cpp
[/code]

Run the binary

[code language=”bash”]
cppcheck cppcheck –enable=all –suppress=missingIncludeSystem ~//your-source-cpp-file.cpp

Checking ~//your-source-cpp-file.cpp …
1/2 files checked 0% done
Checking cppcheck …
[cppcheck:1]: (error) The code contains unhandled character(s) (character code=192). Neither unicode nor extended ascii is supported.
2/2 files checked 100% done
[~//your-source-cpp-file.cpp:65]: (style) The function ‘xxx’ is never used.
[~//your-source-cpp-file.cpp:60]: (style) The function ‘yyy’ is never used.
[~//your-source-cpp-file.cpp:70]: (style) The function ‘abc’ is never used.
[~//your-source-cpp-file.cpp:161]: (style) The function ‘xyz’ is never used.
(information) Cppcheck cannot find all the include files (use –check-config for details)
[/code]
For further details read cppcheck manual.

Leave a Reply