c++ - 运行 valgrind

标签 c++ valgrind

我以前没有用过valgrind,但我需要用它来检查内存泄漏。我运行了以下命令:

G_SLICE=always-malloc G_DEBUG=gc-friendly  valgrind -v --tool=memcheck --leak-check=full --num-callers=40 --log-file=valgrind.log example1
valgrind: example1: command not found

我遵循了该网站的说明: http://www.cprogramming.com/debugging/valgrind.html

这是 example1 文件的样子:

#include <stdlib.h>
int main()
{
    char *x = malloc(100); /* or, in C++, "char *x = new char[100] */
    return 0;
}

我知道我的机器上安装了 valgrind,无论我运行以下命令以确保:

sudo apt-get install valgrind

有人可以吗。指导我如何让 valgrind 工作....谢谢!

最佳答案

你忘了给它你想运行的程序的路径!将 example1 替换为可执行文件的路径。

例如:

G_SLICE=always-malloc G_DEBUG=gc-friendly  valgrind -v \
  --tool=memcheck --leak-check=full --num-callers=40 \
  --log-file=valgrind.log ./example1

关于c++ - 运行 valgrind,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9864793/

相关文章:

c++ - 将随机整数写入文本文件而不重复

c++ - 无法包含 msclr\marshal_cppstd.h - _This_conversion_is_not_supported

c++ - 在地址 0x0 处使用 C++ vector 写入大小无效

c++ - Valgrind 的地 block 工具不会分析我的应用程序

c - Valgrind 检查 C 中的内存泄漏

c - pcap 初始化时出现 Valgrind 错误

c++ - Linux/海湾合作委员会 : Is there a way to check if a build is identical to a previous one on a different machine?

c++ - 使用 typedef 函数指针的不完整类型

c++ - 根据维度启用一个operator()

android - 如何使用 valgrind 启动一个安卓应用程序