1

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
valgrind works

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.


OldPanda
154 声望1 粉丝

南村群童欺我老无力