[英]How to install Valgrind on macOS Mojave(10.14) with Homebrew?
I tried to install Valgrind with brew install Valgrind
and got:我尝试使用brew install 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.
I tried brew install --HEAD Valgrind
.我试过brew install --HEAD Valgrind
。
Instead, after successfully installing the dependencies autoconf
, automake
and libtool
, when it tries to install valgrind, I get a configure error:相反,在成功安装依赖autoconf
、 automake
和libtool
之后,当它尝试安装 valgrind 时,出现配置错误:
Valgrind works on Darwin 10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x and
17.x (Mac OS X 10.6/7/8/9/10/11 and macOS 10.12/13)
My OS is macOS Mojave(10.14), so does it mean that I can't install a functioning Valgrind with Homebrew presently?我的操作系统是 macOS Mojave(10.14),这是否意味着我目前无法使用 Homebrew 安装正常运行的 Valgrind?
A (rather painful) install from source workaround based on this patch , this post and this answer .基于此补丁、此帖子和此答案从源解决方法安装(相当痛苦)。
$ git clone https://github.com/Echelon9/valgrind.git
$ cd valgrind
$ git checkout feature/v3.14/macos-mojave-support-v2
$ ./autogen.sh
$ ./configure --prefix=/where/you/want/it/installed --enable-only64bit
$ make
If you get the following error: No rule to make target '/usr/include/mach/mach_vm.defs'
, you will need to run xcode-select --install
.如果您收到以下错误: No rule to make target '/usr/include/mach/mach_vm.defs'
,您将需要运行xcode-select --install
。 You might need to install Xcode from the app store if you don't already have it.如果您还没有 Xcode,则可能需要从应用商店安装 Xcode。 Once that's done, you will need to edit the coregrind/Makefile
:完成后,您将需要编辑coregrind/Makefile
:
Search for:搜索:
am__append_19 = \
/usr/include/mach/mach_vm.defs \
/usr/include/mach/task.defs \
/usr/include/mach/thread_act.defs \
/usr/include/mach/vm_map.defs
After double checking the below folder exists, prefix every line with:仔细检查以下文件夹是否存在后,在每一行前面加上:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
End result should be:最终结果应该是:
am__append_19 = \
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/mach/mach_vm.defs \
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/mach/task.defs \
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/mach/thread_act.defs \
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/mach/vm_map.defs
Now run make
again and the includes should be found.现在再次运行make
,应该会找到包含的内容。 But that doesn't necessarily mean it will compile.但这并不一定意味着它会编译。 I got the following error:我收到以下错误:
vg_preloaded.c:136:19: error: expected ';' before 'const'
__private_extern__ const char *__crashreporter_info__ = "Instrumented by Valgrind " VERSION;
A fix for this is to add the following line:对此的解决方法是添加以下行:
#define __private_extern__ extern
to the following files:到以下文件:
coregrind/m_syscall.c
coregrind/m_syswrap/syswrap-darwin.c
coregrind/vg_preloaded.c
Finally, you need to cross your fingers hoping no other errors show up:最后,您需要交叉手指,希望不会出现其他错误:
$ make
$ make install
You may use Experimental Version of Valgrind for macOS 10.14.5 Mojave at:您可以在 macOS 10.14.5 Mojave 上使用实验版 Valgrind:
https://github.com/sowson/valgrind https://github.com/sowson/valgrind
The command to use it is:使用它的命令是:
brew install --HEAD https://raw.githubusercontent.com/sowson/valgrind/master/valgrind.rb
It is still experimental and needs some work but for simple projects works already... Enjoy!它仍然是实验性的,需要一些工作,但对于简单的项目来说已经可以了......享受吧!
addition: I found this one worked for me on my OSX 10.14另外:我发现这个在我的 OSX 10.14 上对我有用
brew install --HEAD https://raw.githubusercontent.com/LouisBrunner/valgrind-macos/master/valgrind.rb
A branch that is working to get OSX correct.正在努力使 OSX 正确的分支。 something to tide us over until we get a real valgrind version fixed.一些东西可以让我们渡过难关,直到我们得到一个真正的 valgrind 版本。
I am having the same issue.我有相同的问题。 It seems like valgrind is not compatible with the newest macOS(10.14 Mojave).似乎 valgrind 与最新的 macOS(10.14 Mojave)不兼容。 Tried installing it the High Sierra way ( https://www.gungorbudak.com/blog/2018/04/28/how-to-install-valgrind-on-macos-high-sierra/ ) and got the same output you described.尝试以 High Sierra 方式安装它( https://www.gungorbudak.com/blog/2018/04/28/how-to-install-valgrind-on-macos-high-sierra/ )并获得与您描述的相同的输出. The only solution I can offer you right now is either working on virtual machine ( https://www.virtualbox.org/ ) or using Docker ( https://www.gungorbudak.com/blog/2018/06/13/memory-leak-testing-with-valgrind-on-macos-using-docker-containers/ ).我现在可以为您提供的唯一解决方案是在虚拟机上工作( https://www.virtualbox.org/ )或使用 Docker( https://www.gungorbudak.com/blog/2018/06/13/memory -leak-testing-with-valgrind-on-macos-using-docker-containers/ )。
I have just found a working solution to use VALGRIND on my Mac (Mojave 10.14.6).我刚刚找到了一个在我的 Mac(Mojave 10.14.6)上使用 VALGRIND 的可行解决方案。 Just run this command :只需运行此命令:
brew install --HEAD https://raw.githubusercontent.com/LouisBrunner/valgrind-macos/master/valgrind.rb
(From https://github.com/LouisBrunner/valgrind-macos ) (来自https://github.com/LouisBrunner/valgrind-macos )
Hope it will work for you.希望它对你有用。
As others have mentioned, Louis Brunner maintains a working version at https://github.com/LouisBrunner/valgrind-macos .正如其他人所提到的,Louis Brunner 在https://github.com/LouisBrunner/valgrind-macos维护了一个工作版本。
brew tap LouisBrunner/valgrind
brew install --HEAD LouisBrunner/valgrind/valgrind
This worked for me for MacOS 10.15.7 Catalina.这对我适用于 MacOS 10.15.7 Catalina。
Not a proper solution for macOs, but for the time being, I created a docker image.不是 macOs 的合适解决方案,但目前,我创建了一个 docker 镜像。 After installing docker for macOS, this is how to start valgrind:为 macOS 安装 docker 后,这是启动 valgrind 的方法:
cd </path/to/source/directory/where/you/want/run/valgrind/with>
curl -O https://raw.githubusercontent.com/biocyberman/ValgrindDocker/master/startValgrind
./startValgrind # this will takes time for the first time, because it needs to fetch docker valgrind image
# you will get a root command prompt inside the docker image.
# do what ever you want
# type 'exit' to quit
在Mojave 10.14上工作:
brew install --HEAD https://raw.githubusercontent.com/LouisBrunner/valgrind-macos/master/valgrind.rb
You can follow alex.m's answer to get valgrind, but if you'r using it on a int main() { return 0; }
您可以按照 alex.m 的回答来获取 valgrind,但如果您在int main() { return 0; }
int main() { return 0; }
program, you'll get many weird errors, and non-existing allocs / free. int main() { return 0; }
程序,你会得到很多奇怪的错误,并且不存在分配/免费。
To 'hide' these annoying errors, you can follow theses steps (it's more a workaround than a real fix) (based on this wiki page and some research in Valgrind's source code):要“隐藏”这些烦人的错误,您可以按照以下步骤操作(这更像是一种解决方法而不是真正的修复)(基于此 wiki 页面和 Valgrind 源代码中的一些研究):
int main() { return 0; }
首先,创建并编译一个int main() { return 0; }
int main() { return 0; }
program. int main() { return 0; }
程序。 valgrind --leak-check=full --show-reachable=yes --error-limit=no --gen-supressions=all --log-file=$YOUR_LOG$ $YOUR_BINARY$
.supp
valgrind file:使用这个 gawk 脚本,创建.supp
valgrind 文件: cat ./$YOUR_LOG$ | ./$YOUR_SCRIPT_FILE$ > minimal.supp
minimal.supp
content at the end of $YOUR_VALGRIND_INSTALLATION_PATH$/lib/valgrind/default.supp
file复制粘贴minimal.supp
在年底内容$YOUR_VALGRIND_INSTALLATION_PATH$/lib/valgrind/default.supp
文件And you are done!你已经完成了! Weird and nonexistent errors will be ignored.奇怪的和不存在的错误将被忽略。 If you also want's to remove the non-existing alloc
s, free
s etc, you can directly edit Valgrind's source code.如果您还想删除不存在的alloc
s、 free
s 等,您可以直接编辑 Valgrind 的源代码。 Or just use heapusage
for leak-tracking或者只是使用heapusage
进行泄漏跟踪
As of 2019-NOV-30, it is possible to build against OS X 10.14.6 via https://github.com/sowson/valgrind and https://github.com/LouisBrunner/valgrind-macos截至 2019 年 11 月 30 日,可以通过https://github.com/sowson/valgrind和https://github.com/LouisBrunner/valgrind-macos针对 OS X 10.14.6 进行构建
However , there are many test failures (see the LouisBrunner link), noise during runs, and SEGVs when running against non-trivial programs: installing is, well, installing.但是,有许多测试失败(请参阅 LouisBrunner 链接)、运行期间的噪音以及针对非平凡程序运行时的 SEGV:安装就是安装。 YMMV.天啊。
(适用于莫哈韦沙漠 10.14.6)
brew install --HEAD https://raw.githubusercontent.com/sowson/valgrind/master/valgrind.rb
It seems like this specific version of OSX is problematic with valgrind, so it won't be easy as brew install
the package.似乎这个特定版本的 OSX 与 valgrind 有问题,因此brew install
软件包并不容易。 Fortunately the following way worked for me:幸运的是,以下方法对我有用:
First download need MacOSX10.14 sdk , This comes with XCode but you can also download it here .首先下载需要MacOSX10.14 sdk ,这个是XCode自带的但是你也可以在这里下载。 The path where you unzip it will be referenced as <PATH TO OSX SDK>
解压缩的路径将被引用为<PATH TO OSX SDK>
Then do the following然后执行以下操作
$ git clone https://github.com/Echelon9/valgrind.git
$ cd valgrind
$ git checkout feature/v3.14/macos-mojave-support-v2
$ ./autogen.sh
$ ./configure --prefix=<installation_path> --enable-only64bit
Edit coregrind/Makefile, change this:编辑 coregrind/Makefile,更改为:
am__append_19 = \
/usr/include/mach/mach_vm.defs \
/usr/include/mach/task.defs \
/usr/include/mach/thread_act.defs \
/usr/include/mach/vm_map.defs
to到
am__append_19 = \
<PATH TO OSX SDK>/MacOSX10.14.sdk/usr/include/mach/mach_vm.defs \
<PATH TO OSX SDK>/MacOSX10.14.sdk/usr/include/mach/task.defs \
<PATH TO OSX SDK>/MacOSX10.14.sdk/usr/include/mach/thread_act.defs \
<PATH TO OSX SDK>/MacOSX10.14.sdk/usr/include/mach/vm_map.defs
Then run然后运行
$ make
$ make install
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.