Valgrind 真是C/C++内存调试的利器


1. 可以下载RPM 包,直接安装
2. 编译和安装Valgrind




(1)从首页下载, 或者wget http://valgrind.org/downloads/valgrind-3.8.1.tar.bz2, 获取
(2)解压bzip2 -d valgrind-3.8.1.tar.bz2
(2) tar -xvf valgrind-3.8.1.tar 进入源代码目录 or tar jxvf valgrind-3.***.tar.bz2 直接解压
(4)运行./configure配置Valgrind,具体参数信息详见INSTALL文件。一般只需要设置--prefix=/home/you/want/it/installed
(5)make,编译Valgrind
(6)make install,安装Valgrind
(7)输入valgrind --version; 如果有老版本,则需要注意环境变量的设置,保证新安装的生效。


常见问题:
valgrind: failed to start tool 'memcheck' for platform 'amd64-linux': No such file or directory
一个是版本太低,不支持64bit
二是安装问题,参考:https://webcache.googleusercontent.com/search?q=cache:6hb5lNVRBDcJ:eatmyrandom.blogspot.com/2010/10/valgrind-and-failed-to-start-tool.html+&cd=1&hl=en&ct=clnk&gl=hk


This is Google's cache of http://eatmyrandom.blogspot.com/2010/10/valgrind-and-failed-to-start-tool.html. It is a snapshot of the page as it appeared on 17 Nov 2012 20:22:04 GMT. The current page could have changed in the meantime. Learn more
Tip: To quickly find your search term on this page, press Ctrl+F or ?-F (Mac) and use the find bar.


Text-only version
 
EatMyRandom Blog




Oct 29, 2010
valgrind and the "failed to start tool 'memcheck'..." error


I've just decided to update valgrind with the latest version and got the following error:
"failed to start tool 'memcheck' for platform 'amd64-linux': No such file or directory"


It looks like the error is pretty much famous. I saw it also on some machines we use at work. I actually desperately needed valgrind, therefore decided to find out what the problem is.


Checking $PATH and $LD_LIBRARY_PATH didn't help - everything was fine. But what really helped is this message, which I should have read before installing valgrind :)


Important!  Do not move the valgrind installation into a place
different from that specified by --prefix at build time.  This will
cause things to break in subtle ways, mostly when Valgrind handles
fork/exec calls
(valgrind's README file)


But you know, I didn't really moved the installation. What I did was just configure and make, but after that I reconfigured it with prefix and didn't issued "make distclean" before reconfiguring :)


So, the recipe is simple. 
If you do "./configure" -- > "make install", than it should be just fine.
But if you do "./configure" -- > "make" -- > "./configure --prefix=..." -- > "make install", than most probably you will get this error message, see the subject.


Well you built valgrind and changed your mind later with the prefix, than don't forget to "make distclean" the source.


Hope it helps and you will not loose hours looking for reasons of the error ;)


你可能感兴趣的:(C/C++相关(语言,工具等))