(Ubuntu64)valgrind安装+编译64位 32位版本

本文详细介绍了如何在Ubuntu64位系统上安装Valgrind 3.12.0,包括下载、编译、安装到环境变量配置的步骤。此外,还讲解了在运行32位程序时遇到的问题,如需安装i386库以避免错误,并展示了如何解决overwrite失败的问题。最后,通过示例展示了如何使用Valgrind进行内存检测,包括64位和32位程序的运行结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装编译步骤:

wget http://valgrind.org/downloads/valgrind-3.12.0.tar.bz2

 

tar xvf valgrind-3.12.0.tar.bz2

 

cd valgrind-3.12.0

 

sudo apt-get install automake

 

./autogen.sh

 

./configure --prefix=/<pathto>/valgrind-3.12.0

 

make

 

make install

 

添加至环境变量:

sudo gedit ~/.bashrc

添加:

export PATH=$PATH:/<pathto>/valgrind-3.12.0/bin

export VALGRIND_LIB="/<pathto>/valgrind-3.12.0/lib/valgrind"

source .bashrc

检测是否成功编译:

valgrind --version

测试用例:

#include <stdlib.h>

int main()

{

int * pArray =malloc(sizeof(int) * 5);

pArray[5] = 1;

int * pInt ;

int x = *pInt;

* pInt = 2;

return 0;

}

编译:gcc -g -o test main.c

检测:valgrind --leak-check=yes ./test

检测32位程序的时候需要安装对应的i386库否则会提示错误:

==3062== Memcheck, a memory error detector
==3062== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==3062== Using Valgrind-3.12.0 and LibVEX; rerun with -h for copyright info
==3062== Command: ./test
==3062== 

valgrind:  Fatal error at startup: a function redirection
valgrind:  which is mandatory for this platform-tool combination
valgrind:  cannot be set up.  Details

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值