macOS Sierra 上的 Valgrind

Valgrind on macOS Sierra

我遵循本指南:

valgrind installation guide

下载包后,我有 运行 sh 脚本,但是当我启动 make install 命令时,它无法创建文件夹,因为它没有许可(即使我使用了 sudo 命令)。

此外,我尝试使用 brew,但出现此错误:

valgrind: This formula either does not compile or function as expected on macOS versions newer than El Capitan due to an upstream incompatibility.

Error: An unsatisfied requirement failed this build.

您可以从 website 下载 Valgrind 的最新版本。然后,您可以 ./autogen.sh 安装 Valgrind。我个人没遇到什么需要make

然而,不幸的是,即使是最新版本的 Valgrind 在 Mac OS Sierra 上也不是很可用。原因是Apple没有发布导致Valgrind崩溃的那部分源代码,没有它,Valgrind的维护者几乎无能为力。您可以阅读有关围绕该问题的讨论的更多信息 here .

因为Mac OS内核在Apple Public Source License下面,总有一天要开源的。因此,Valgrind 的 Sierra 兼容版本只是时间问题。

目前,我在 Linux 下使用 Valgrind。这就是我现在能提出的所有建议。

最新的 Valgrind(git 版本 3.13.0)现在可以在 MacOS Sierra 上运行,但需要安装 Xcode 命令行工具(需要安装 headers)。

运行 在构建 Valgrind 之前:

xcode-select --install

感谢 this post

如果你碰巧还在 Sierra 上,这行得通(但在 High Sierra 上不行),就这样吧

$ brew 安装 valgrind

 valgrind: This formula either does not compile or function as expected on macOS
 versions newer than Sierra due to an upstream incompatibility.
 Error: An unsatisfied requirement failed this build.

更新:似乎它现在也适用于 "High Sierra" OOTB,它现在说:

...versions newer than High Sierra due to an upstream incompatibility...

如果您收到类似于

的错误

valgrind: This formula either does not compile or function as expected on macOS versions newer than Sierra due to an upstream incompatibility.

您可以尝试解决方法 brew install --HEAD valgrind 我在此处找到此信息 https://www.gungorbudak.com/blog/2018/04/28/how-to-install-valgrind-on-macos-high-sierra/

mac 上 valgrind 的简单替代方法称为 'leaks'。这是一个 command-line 工具,所以如果您还没有安装 xcode command-line 工具,请使用 'xcode-select --install'.

然后,为了测试泄漏,只需编译你的程序然后 运行 'leaks -atExit -- ./your_prog'