23

I'm trying to install Valgrind on a Mac with Snow Leopard but am getting an error. This is what I'm typing into Terminal.

$ curl -O http://valgrind.org/downloads/valgrind-3.8.1.tar.bz2
$ md5sum valgrind-3.8.1.tar.bz2
$ tar -xjvf valgrind-3.8.1.tar.bz2
$ cd valgrind-3.8.1
$ ./configure
$ make

This is the error I get.

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

How can I correct this error?

Jack Stout
  • 1,265
  • 3
  • 12
  • 25

4 Answers4

87

Make sure to install the command line tools.

xcode-select --install
Volte
  • 1,905
  • 18
  • 25
  • 4
    Correct, this is the recommended fix from the Valgrind developers. The alternatives above are brittle and not guaranteed to work with future Xcode releases. – e76d587d9 Sep 28 '15 at 07:46
  • 4
    This worked perfectly for me. This should be the accepted answer. – CGTheLegend Oct 04 '15 at 11:02
  • The computer I was using at the time of this question has already gone through the chipper but, even if it was around, I doubt that this answer would have worked given the nature of my specific issue. Due to a business decision that Apple admitted was misguided, a specific version of Snow Leopard could not get Xcode without paying the full developer fee. The pay wall was removed in the next version, but was never taken off that one version; the version I had. My solution was to dual boot Ubuntu and continue my project. – Jack Stout Mar 08 '16 at 19:36
  • I am using using Mavericks and XCode 6. After I ran the xcode-select --install, it was still asking for the defs file mentioned above as the makefile is looking for them in the directory /usr/include. one can softlink by doing ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOS10.9.sdk/usr/include include so the makefile can find the relevant files. – g5thomas Mar 30 '17 at 21:28
  • This didn't work for me, but this did: https://stackoverflow.com/a/50548805/4723722 – TmsKtel May 28 '19 at 12:40
5

The best way to get valgrind compiled properly is to use the 'xcode-select --install' command as mentioned in the above answer. However, as sub-optimal hack, you can get it compiled by downloading the following files from OSX /mach source into /usr/include/mach (create this directory):

mach_vm.defs    
task.defs
thread_act.defs
vm_map.defs

It's a slightly dirty hack, but it should get you going if you really don't want to download/install the large Xcode original files.

Pete855217
  • 1,570
  • 5
  • 23
  • 35
4

Apparently, to compile on a Macintosh, valgrind needs the file /usr/include/mach/mach_vm.defs to be present. While I haven't been able to find specific references to mach_vm.defs being part of XCode specifically, it seems that most of the usual contents of /usr/include/mach are installed when XCode is.

If for some reason you can't install XCode on your machine, you can get most of the source files for that particular directory from this part of apple's open source website.

Dan
  • 12,157
  • 12
  • 50
  • 84
  • This was the problem. Unfortunately, I ran into another problem. If I can't solve it, I'll post a new question. – Jack Stout Nov 17 '12 at 16:37
  • Had a similar issue. This answer helped, but so did some of the comments on this page. http://calvinx.com/2014/05/04/valgrind-on-mac-os-x-10-9-mavericks/ Location of xcode install for /usr/include/mach = /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include – Alex Hornbake Jun 10 '15 at 02:14
  • 1
    This issue arises again as in the new El Capitan OS not even sudo can create the directory '/usr/include' – David Schumann Oct 30 '15 at 19:41
  • 6
    Scroll down and use the other answer! It is better. – Matthew Gunn Nov 24 '15 at 03:48
2

Ever since the System Integrity Protection system was put in place on OSX, the user, not even as root, can modify /usr. Thus, modifying /usr/include/mach to add the necessary files becomes impossible. The only alternative is now to edit the makefile itself.

The Makefile at hand should be located at coregrind/Makefile, and the mach files should be located near /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/ (replace MacOSX10.12.sdk with the appropriate version of OSX).

There should be a symbol named am__append_17 defined around line 160 or so (might be elsewhere for different versions).

It should look something like this:

am__append_17 = \
    /usr/include/mach/mach_vm.defs \
    /usr/include/mach/task.defs \
    /usr/include/mach/thread_act.defs \
    /usr/include/mach/vm_map.defs

Replace each instance of /usr/include with /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/, so that it looks like:

am__append_17 = \
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/mach/mach_vm.defs \
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/mach/task.defs \
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/mach/thread_act.defs \
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/mach/vm_map.defs

After this, valgrind should compile properly

Lux
  • 1,540
  • 1
  • 22
  • 28