I tried to install Valgrind with brew install Valgrind
and got :
valgrind: This formula either does not compile or function as expected on macOS versions newer than Sierra due to an upstream incompatibility. Error: An unsatisfied requirement failed this build.
I tried brew install --HEAD Valgrind
.
Instead, after successfully installing the dependencies autoconf
, automake
and libtool
, when it tries to install valgrind, I get a configure error:
Valgrind works on Darwin 10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x and 17.x (Mac OS X 10.6/7/8/9/10/11 and macOS 10.12/13)
My OS is macOS Mojave(10.14), so does it mean that I can't install a functioning Valgrind with Homebrew presently?
x and later), ARM64/Android, X86/Android (4.0 and later), MIPS32/Android, X86/FreeBSD, AMD64/FreeBSD, X86/Darwin and AMD64/Darwin (Mac OS X 10.12). Valgrind is Open Source / Free Software, and is freely available under the GNU General Public License, version 2.
Valgrind is a programming tool for memory debugging, memory leak detection and profiling. Its installation for macOS High Sierra seems problematic and I wanted to write this post to tell the solution that worked for me. I use Homebrew to install it which is the recommended way and the solution also uses it.
A (rather painful) install from source workaround based on this patch, this post and this answer.
$ git clone https://github.com/Echelon9/valgrind.git $ cd valgrind $ git checkout feature/v3.14/macos-mojave-support-v2 $ ./autogen.sh $ ./configure --prefix=/where/you/want/it/installed --enable-only64bit $ make
If you get the following error: No rule to make target '/usr/include/mach/mach_vm.defs’
, you will need to run xcode-select --install
. You might need to install Xcode from the app store if you don't already have it. Once that's done, you will need to edit the coregrind/Makefile
:
Search for:
am__append_19 = \ /usr/include/mach/mach_vm.defs \ /usr/include/mach/task.defs \ /usr/include/mach/thread_act.defs \ /usr/include/mach/vm_map.defs
After double checking the below folder exists, prefix every line with:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
End result should be:
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
Now run make
again and the includes should be found. But that doesn't necessarily mean it will compile. I got the following error:
vg_preloaded.c:136:19: error: expected ';' before 'const' __private_extern__ const char *__crashreporter_info__ = "Instrumented by Valgrind " VERSION;
A fix for this is to add the following line:
#define __private_extern__ extern
to the following files:
coregrind/m_syscall.c
coregrind/m_syswrap/syswrap-darwin.c
coregrind/vg_preloaded.c
Finally, you need to cross your fingers hoping no other errors show up:
$ make $ make install
You may use Experimental Version of Valgrind for macOS 10.14.5 Mojave at:
https://github.com/sowson/valgrind
The command to use it is:
brew install --HEAD https://raw.githubusercontent.com/sowson/valgrind/master/valgrind.rb
It is still experimental and needs some work but for simple projects works already... Enjoy!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With