c++ - How to run valgrind with basic c example? -
installation:
bzip2 -d valgrind-3.10.1.tar.bz2 tar -xf valgrind-3.10.1.tar
then:
./configure make make install
or simplier
sudo apt-get install valgrind
how run valgrind on simple program example1.c
#include <stdlib.h> int main() { char *x = malloc(100); /* or, in c++, "char *x = new char[100] */ return 0; }
run:
valgrind --tool=memcheck --leak-check=yes example1 valgrind: example1: command not found
output console:
valgrind: example1: command not found
it looks good. need add ./
before executable. without it, valgrind
fails find , reports 'command not found'
.
valgrind --tool=memcheck --leak-check=yes ./example1 ^
Comments
Post a Comment