Install Valgrind on Mac

Life is hard.

For whom may only concern the final solution, please check the last part--The Whole Procedure.

I got stuck in Exercise 4: Introducing Valgrind when trying to install valgrind on my computer. The tarball downloaded from the official site claims working fine on Mac OS X 10.9, but it doesn't work for me when I tried to install it. I spent four hours on refering to a lot of similar problems online and luckily, I make valgrind run on my MacBook.

At first, I run the commands provided by the book.

# 1) Download it (use wget if you don't have curl)
curl -O http://valgrind.org/downloads/valgrind-*.*.*.tar.bz2
# use md5sum to make sure it matches the one on the site
md5sum valgrind-*.*.*.tar.bz2
# 2) Unpack it.
tar -xjvf valgrind-*.*.*.tar.bz2
# cd into the newly created directory
cd valgrind-*.*.*
# 3) configure it
./configure
# 4) make it
make
# 5) install it (need root)
sudo make install

But things will go wrong after executing the 4th command--make, and the error message goes like this.

Making all in coregrind
make[2]: *** No rule to make target `/usr/include/mach/mach_vm.defs', needed by `m_mach/mach_vmUser.c'.  Stop.
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

Then I found a post from Calvin. Same OS, same valgrind, however, same error occured after make. I noticed there's no such a directory called /usr/include in my computer. To fix this, I need to install command line tools by running xcode-select --install.

Unlucky student always suffers. Because god wish me to learn more things about valgrind installation, I encountered some new message after following instructions in Calvin, still right behind make.

Undefined symbols for architecture x86_64:
  "_voucher_mach_msg_set", referenced from:
      __kernelrpc_mach_vm_allocate in
libcoregrind-amd64-darwin.a(libcoregrind_amd64_darwin_a-mach_vmUser.o)
      __kernelrpc_mach_vm_deallocate in
libcoregrind-amd64-darwin.a(libcoregrind_amd64_darwin_a-mach_vmUser.o)
      __kernelrpc_mach_vm_protect in
libcoregrind-amd64-darwin.a(libcoregrind_amd64_darwin_a-mach_vmUser.o)
......

There's also a bug report page for it. The processor of my computer is a 64-bit one, so I changed the flags after ./configure to --disable-tls --enable-only64bit --build=amd64-darwin. Then guess what? Valgrind works!!

Command: valgrind ./ex3

The Whole Procedure

I refered to some steps in Calvin.

# Make sure I have autoconf and automake both installed.
sudo port -v install automake  
sudo port -v install autoconf 
# Grab Frederic's patched valgrind on his "homebrew" branch 
cd your-work-directory
git clone https://github.com/fredericgermain/valgrind/ -b homebrew
cd valgrind
# Because he placed VEX as a git submodule, we have to make sure we clone it too
git submodule init
git submodule update
# With VEX submodule now available, we can compile valgrind
./autogen.sh
./configure --disable-tls --enable-only64bit --build=amd64-darwin
make
sudo make install

Now I can guess a little bit why the book name is Learn C The Hard Way.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值