Author Topic: I have installed CppCheck but get an error when I try to run it in.  (Read 9825 times)

Offline Dice

  • Multiple posting newcomer
  • *
  • Posts: 14
I'm using Code::Blocks 13.12 with MinGW -w64 (TDM-GCC suite) compiler on Windows 7 (64bit).  My goal is to use CppCheck to help me find memory leaks in my programs.  I downloaded the 64-bit version of CppCheck from here: http://cppcheck.sourceforge.net/.  I then installed CppCheck from the installer.  Next I opened Code::Blocks and went to --> Settings --> Environment --> CppCheck.  In the field labeled "CppCheck application:" I clicked "..." and went to the place where CppCheck was installed and selected "cppcheck.exe".  I then opened up a project that I'm working on, built it using "Debug", and went to --> Plugins --> CppCheck.  I then get an error message that says "The program can't start because MSVCP140.dll is missing from your computer.  Try reinstalling the program to fix this problem."  I click "OK" and the same message pops up again.  I then get another popup that says "Failed to parse cppcheck XML file.  Probably it's not produced correctly."  I checked the directory where CppCheck is installed and I didn't see "MSVCP140.dll".  I then checked the folders where my compiler is installed and didn't see "MSVCP140.dll".  I then did a google search for "MSVCP140.dll" and found some results saying that I need to get this run-time library by downloading Visual Studio.  I didn't download Visual Studio because I'd rather use Code::Blocks.  Has anyone else had this issue?  How can I get CppCheck to work?  Does Code::Blocks have another plugin option to check for memory leaks on Windows builds?

Offline raynebc

  • Almost regular
  • **
  • Posts: 217
Re: I have installed CppCheck but get an error when I try to run it in.
« Reply #1 on: January 16, 2016, 10:13:55 am »
You don't have to install the entire Visual Studio suite, just the VC++ runtime:
https://www.microsoft.com/en-us/download/details.aspx?id=48145

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: I have installed CppCheck but get an error when I try to run it in.
« Reply #2 on: January 16, 2016, 01:17:28 pm »
You don't have to install the entire Visual Studio suite, just the VC++ runtime:
https://www.microsoft.com/en-us/download/details.aspx?id=48145

It is very simple: If you install the 32 bit version of CppCheck these DLL's are included. If you install the 64 bit they are missing (probably for a good reason). Now, for Cppcheck to find these DLL's when called from another folder (or tool, like C::B), you'll need to add the path to the CppCheck folder to...
- either you Windows PATH environment, or
- use the envvars plugin to extend the PATH environment for the focus inside C::B or
- add the path to the CppCheck folder (with the DLL's included) to the compiler path's as this:
Settings -> Compiler -> [Your compiler] -> Toolchain executables -> Tab "Additonal paths"

(For the latter to work it maybe required to run the compiler first.... so that is the worst option.)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Goofus Maximus

  • Single posting newcomer
  • *
  • Posts: 5
Re: I have installed CppCheck but get an error when I try to run it in.
« Reply #3 on: January 19, 2016, 04:18:41 am »
I ended up just downloading the source code zip file.  They have a codeblocks project file included in it, so I just unzipped, opened the cbp file and compiled the project with my default TDM Mingw W64 compiler, then pointed the cppcheck path to that folder.

I don't have a fancy GUI, but it works with codeblocks...

Edit: and for some reason, this self-compiled cppcheck loves to say "too many configs".  I ended up downloading the 32 bit version, since codeblocks is 32 bit as well, and this version goes into great detail about just what all is wrong with WX code, just from the simple "new wxWidgets project" template code, so it's working just fine.

Edit of the edit:  Okay, I admit I am an idiot.  Can someone give a more intuitive example of how to restrict ifdef hell to just what the compiler is currently using?  The manual is lacking in real-world examples of command line usage...
« Last Edit: January 19, 2016, 09:48:32 pm by Goofus Maximus »

Offline Dice

  • Multiple posting newcomer
  • *
  • Posts: 14
Re: I have installed CppCheck but get an error when I try to run it in.
« Reply #4 on: January 20, 2016, 06:41:19 am »
Thanks for the help everyone.  This is getting more complicated than I'm comfortable with.  I think I'll just end up writing a wrapper for malloc() and free() to look for memory leaks.

Offline CJS

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: I have installed CppCheck but get an error when I try to run it in.
« Reply #5 on: January 20, 2016, 09:15:38 am »
I've used Dr. Memory to check for memory leaks - it identifies uninitialized memory, accesses to unaddressable memory, accesses to freed memory, double frees, memory leaks, handle leaks on Windows etc.

It works with binaries on Windows, Linux, or Mac (it currently targests 32-bit applications only, although I suppose you could get some useful information about a 64-bit target by building a 32-bit version as there would be memory leaks with common causes regardless of architecture).

Home page:
http://drmemory.org/

Download link from home page:
https://github.com/DynamoRIO/drmemory/wiki/Downloads

I have checked it out on Norton safe web and Web of Trust and found no issues.

The version I used was 1.8.0-8

Sometimes it crashed before finishing but still provided useful log results.
« Last Edit: January 20, 2016, 09:19:09 am by CJS »

Offline raynebc

  • Almost regular
  • **
  • Posts: 217
Re: I have installed CppCheck but get an error when I try to run it in.
« Reply #6 on: January 20, 2016, 08:14:09 pm »
Similarly, memwatch is a small bit of source code you can add to your project and it reports on memory errors like wild frees, double frees, buffer overflows, etc.

However, you are aware that you can run cppcheck outside of Code::Blocks, right?

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: I have installed CppCheck but get an error when I try to run it in.
« Reply #7 on: January 20, 2016, 11:30:16 pm »
Just to make some things clear:
1) CppCheck is a statc code analyzer, so cppcheck is unaware what compiler you are using for your program or what your platform is
2) CppCheck is a stand alone program, the  c::b plugin simply calls cppcheck.exe on all project files and parses the log so errors like:
The program can't start because MSVCP140.dll is missing from your computer.  Try reinstalling the program to fix this problem." 
is a runtime error of cppcheck not c::b. This has nothing  to do with your compiler or with codeblocks. It says simply that your cppcheck version is compiled with the visual studio 2015 runtime. This also don't mean that you have to install Visual Studio, or the Visual Studio compiler. You simply have to install the Visual Studio Runtime libraries, (a batch of dlls). You can find them here: https://www.microsoft.com/en-us/download/details.aspx?id=48145 If you install them cppcheck should run without problems

However, you are aware that you can run cppcheck outside of Code::Blocks, right?
No he can't because his VC Runtime is missing....

Thanks for the help everyone.  This is getting more complicated than I'm comfortable with.  I think I'll just end up writing a wrapper for malloc() and free() to look for memory leaks.
You are thinking way to complicated... Simply install the runtime ;)

BUT: For finding memory leaks cppcheck is not the best tool. On linux i would recommend Valgrind but this tool does not exists on windows. So Dr. Memory is a good alternative or as you said overwriting malloc and free...

greetings

Offline raynebc

  • Almost regular
  • **
  • Posts: 217
Re: I have installed CppCheck but get an error when I try to run it in.
« Reply #8 on: January 21, 2016, 12:57:40 am »
Sure, he could use cppcheck after he installed the runtime that was linked very early into the thread.  What I'm saying is his posts made it sound like he thought Cppcheck could only be invoked from within Code:blocks.

I've never heard of a Valgrind equivalent for Windows, but MemWatch is basically just that:  A wrapper system for the standard C memory allocation and freeing routines (ie. malloc() and free()).

JangoUnchained

  • Guest
Re: I have installed CppCheck but get an error when I try to run it in.
« Reply #9 on: March 30, 2016, 01:06:33 pm »
I faced with this problem too. There are two good ways to solve it. First of all you should try to reinstall MS c++ visual studio 2015. It helps usually. It this didn't helped you, try to find missing file in internet, on a well trusted websites, for example fix4dll.com/msvcp140_dll and add it to your system folder depending on windows version.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: I have installed CppCheck but get an error when I try to run it in.
« Reply #10 on: March 30, 2016, 06:11:41 pm »
A trusted place for a dll produced by Microsoft is microsoft.com and nothing else!
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]