Valgrind on Mac OS X 10.10 Yosemite

· by Mario Ranftl · 313 words, 2 min ·  c  programming

You want to hack with C and Valgrind on OS X 10.10 Yosemite? Well, you’ll definitely run into problems getting it for your very platform, as there is no official stable release out there yet. Consequentially these is no receipt for Homebrew (which is great anyways, get it!), hence you need to manually build that nifty tool from the latest trunk SVN repository.

Here’s how to do that (needs installation of Xcode’s Command Line Tools):

# Check out their repo...
$ svn co svn://svn.valgrind.org/valgrind/trunk valgrind-trunk
# and hop into it.
$ cd valgrind-trunk

# You need to have autoconf and automake installed to build Valgrind
# This example uses Homebrew to install these dependencies
# (MacPorts should also work)
# (Permission error? add sudo!)
$ brew install automake
$ brew install autoconf

# run autogen.sh in valgrind-trunk
$ ./autogen.sh

# Tricky, there are some hard wired paths in the Valgrind sources.
# You need to symlink the mach folder in your XCode SDK to /usr/include/mach
# Be sure to use the proper Xcode SDK "MacOSX10.10.sdk" in the path!
$ ln -sv /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/mach /usr/include/mach

# Run configure + set install paths in valgrind-trunk
$ ./configure --prefix=/usr/local

# Run Make and make install (permission error? add sudo!) in valgrind-trunk
$ make
$ make install

# Check it works
$ valgrind --version
valgrind-3.11.0.SVN

Still on OS X 10.9 Mavericks? Then you might want to check out Calvin’s great How-To.
Background: Currently relearning C the hard way.

EDIT 2015-01-23: Seems like a lot of people assert that Valgrind is completely supported on Mac OS X (although unstable trunk build) and works out of the box (like in Linux). Both assertions are not true! Valgrind will show false positive memory leaks in OS X’s system libraries (these are out of your control), unless you define a suppression file. Have a look at Taras’ How-To to generate such a file!

  About the author

Mario Ranftl is a dedi­cated Aus­trian IT pro­fessional with con­sider­able ex­peri­ence in a range of soft­ware develop­ment en­viron­ments and a special­ization in web tech­nologies. He con­trib­utes to Open Source pro­jects on GitHub and loves to cre­atively solve chal­lenging prob­lems. You can easily reach him via Email.

  Share and subscribe