Compile and install valgrind on macOS Mojave (10.14.2)

栏目: C · 发布时间: 6年前

内容简介:本文是给想在Mojave上编译安装valgrind的人一个参考。个人因为《Hands on concurrency with Rust》这本书的原因,需要安装valgrind。但是现在(2019/2/9)稳定版本的valgrind尚未支持Mojave,即不能通过Homebrew安装。valgrind的bug tracker里有这个问题的下载对应的repository,checkout到修改版的branch上

本文是给想在Mojave上编译安装valgrind的人一个参考。

个人因为《Hands on concurrency with Rust》这本书的原因,需要安装valgrind。但是现在(2019/2/9)稳定版本的valgrind尚未支持Mojave,即不能通过Homebrew安装。valgrind的bug tracker里有这个问题的 追踪 , 但是看状态估计离正式发布还需要时间(开源项目常有的事情,缺少资源,哎)。对话中给了一个github上的commit,看起来可以使用。

下载对应的repository,checkout到修改版的branch上

git clone https://github.com/Echelon9/valgrind.git
cd valgrind
git checkout feature/v3.14/macos-mojave-support-v2

按照valgrind 自身网站上的说明 ,接下来是常规的compile install。

./autogen.sh
./configure --prefix=foo
make
make install

如果你按照顺序执行的话,在make可能会碰到如下两个问题,所以在执行之前,建议先看一下可能碰到的问题

1. No rule to make target `/usr/include/mach/mach_vm.defs’

简单来说,就是没有找到定义文件。按照stackoverflow上 一个问题的说法 ,你可以通过

xcode-select --install

解决,但是答案针对的不是Mojave,所以Mojave除了通过上述命令安装XCode之外,还需要解答中另外一个解决方案,即修改coregrind/Makefile(此文件在./configure之后生成)中mach_vm.defs的路径,具体如下

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

也就是在原本 /usr/include/mach/mach_vm.defs 等文件前加上 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk 前缀,你可以 ls 一下看一下文件是否存在。

2. vgpreload_core_x86_darwin_so-vg_preloaded.o ld: symbol(s) not found for architecture i386

这个问题比较隐蔽,google搜不出来什么东西。直接看错误信息的话,大概知道MacOS下无法链接i386的程序,因为比较新的MacOS基本上只有x86_64。直接的解决方法是不让valgrind去编译i386架构的程序。

如果你留意了 ./configure 最后的输出的话,可以看到Secondary build arch

         Maximum build arch: amd64
         Primary build arch: amd64
       Secondary build arch:
                   Build OS: darwin
     Link Time Optimisation: no
       Primary build target: AMD64_DARWIN
     Secondary build target:
           Platform variant: vanilla
      Primary -DVGPV string: -DVGPV_amd64_darwin_vanilla=1
         Default supp files: exp-sgcheck.supp xfree-3.supp xfree-4.supp darwin10-drd.supp darwin18.supp

假如Secondary build arch不像上面那样为空的话,比如是i386,那么make时会出现以上问题。

在 configure 文件中,valgrind的注释提到在MacOS下会同时编译i386和x86_64,这是问题的根本原因,或者说valgrind在Mojave下编译的坑。幸好 configure 提供了只编译64位的选项,不需要修改 configure 文件。

总结一下,你要做的是

./autogen.sh
./configure --prefix=foo --enable-only64bit
# 修改coregrind/Makefile
make
make install

小结

老实说很后悔升级到了Mojave,MacBook的睡死,突然mic不能使用等问题,现在又来一个valgrind……

不管怎么说,希望本文对你有所帮助。


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Usability for the Web

Usability for the Web

Tom Brinck、Darren Gergle、Scott D. Wood / Morgan Kaufmann / 2001-10-15 / USD 65.95

Every stage in the design of a new web site is an opportunity to meet or miss deadlines and budgetary goals. Every stage is an opportunity to boost or undercut the site's usability. Thi......一起来看看 《Usability for the Web》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

html转js在线工具
html转js在线工具

html转js在线工具