【问题标题】:How to install Valgrind on macOS Mojave(10.14) with Homebrew?如何使用 Homebrew 在 macOS Mojave(10.14) 上安装 Valgrind?
【发布时间】:2019-03-14 21:09:51
【问题描述】:

我尝试使用brew install Valgrind 安装 Valgrind 并得到:

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.

我试过brew install --HEAD Valgrind

相反,在成功安装依赖项 autoconfautomakelibtool 后,当它尝试安装 valgrind 时,出现配置错误:

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)

我的操作系统是 macOS Mojave(10.14),这是否意味着我目前无法使用 Homebrew 安装正常运行的 Valgrind?

【问题讨论】:

标签: macos homebrew valgrind memory-leak-detector


【解决方案1】:

正如其他人所提到的,Louis Brunner 在https://github.com/LouisBrunner/valgrind-macos 维护了一个工作版本。

brew tap LouisBrunner/valgrind
brew install --HEAD LouisBrunner/valgrind/valgrind

这对我适用于 MacOS 10.15.7 Catalina。

【讨论】:

    【解决方案2】:

    (适用于 mojave 10.14.6)

    brew install --HEAD https://raw.githubusercontent.com/sowson/valgrind/master/valgrind.rb
    

    【讨论】:

      【解决方案3】:

      您可以按照 alex.m 的回答获取 valgrind,但如果您在 int main() { return 0; } 程序上使用它,您会收到许多奇怪的错误,并且不存在 allocs / free。

      要“隐藏”这些烦人的错误,您可以按照以下步骤操作(这更像是一种变通方法而不是真正的修复方法)(基于 this wiki page 和对 Valgrind 源代码的一些研究):

      • 首先,创建并编译一个int main() { return 0; } 程序。
      • 执行以下命令(创建包含错误抑制的文件):

      valgrind --leak-check=full --show-reachable=yes --error-limit=no --gen-supressions=all --log-file=$YOUR_LOG$ $YOUR_BINARY$

      cat ./$YOUR_LOG$ | ./$YOUR_SCRIPT_FILE$ > minimal.supp

      • $YOUR_VALGRIND_INSTALLATION_PATH$/lib/valgrind/default.supp 文件末尾复制并粘贴minimal.supp 内容

      你就完成了!奇怪和不存在的错误将被忽略。 如果您还想删除不存在的allocs、frees 等,您可以直接编辑 Valgrind 的源代码。或者只是使用heapusage 进行泄漏跟踪

      【讨论】:

        【解决方案4】:

        我刚刚找到了在我的 Mac (Mojave 10.14.6) 上使用 VALGRIND 的有效解决方案。只需运行此命令:

        brew install --HEAD https://raw.githubusercontent.com/LouisBrunner/valgrind-macos/master/valgrind.rb
        

        (来自https://github.com/LouisBrunner/valgrind-macos

        希望它对你有用。

        【讨论】:

          【解决方案5】:

          截至 2019 年 11 月 30 日,可以通过https://github.com/sowson/valgrindhttps://github.com/LouisBrunner/valgrind-macos 针对 OS X 10.14.6构建

          然而,有很多测试失败(参见 LouisBrunner 链接)、运行过程中的噪音以及针对非平凡程序运行时的 SEGV:安装 是,嗯,安装。 YMMV。

          【讨论】:

            【解决方案6】:

            补充:我发现这个适用于我的 OSX 10.14

            brew install --HEAD https://raw.githubusercontent.com/LouisBrunner/valgrind-macos/master/valgrind.rb
            

            致力于使 OSX 正确的分支。在我们修复真正的 valgrind 版本之前,我们可以渡过难关。

            【讨论】:

            • 遗憾的是,现在无法使用 Xcode 11.2.1 在 macOS 10.14.6 上构建。
            【解决方案7】:

            您可以在以下位置使用适用于 macOS 10.14.5 Mojave 的实验版 Valgrind:

            https://github.com/sowson/valgrind

            使用它的命令是:

            brew install --HEAD https://raw.githubusercontent.com/sowson/valgrind/master/valgrind.rb
            

            它仍然是实验性的,需要一些工作,但对于简单的项目已经可以工作了......享受吧!

            【讨论】:

            • 今天我与带有补丁的原始 valgrind 存储库同步并使用 Mojave 10.14.6 进行了测试,问题是它仍然适用于简单的项目,但不适用于复杂的项目,我可能有人作为贡献者加入以提供帮助? :D.
            • 上面写着Error: The following directories are not writable by your user: /usr/local/share/man/man5
            【解决方案8】:

            基于this patchthis postthis 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
            

            如果您收到以下错误:No rule to make target '/usr/include/mach/mach_vm.defs’,则需要运行 xcode-select --install。如果您还没有 Xcode,则可能需要从应用商店安装 Xcode。完成后,您需要编辑coregrind/Makefile

            搜索:

            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
            

            在仔细检查以下文件夹是否存在后,在每一行添加前缀:

            /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
            

            最终结果应该是:

            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
            

            现在再次运行make,应该会找到包含的内容。但这并不一定意味着它会编译。我收到以下错误:

            vg_preloaded.c:136:19: error: expected ';' before 'const'
             __private_extern__ const char *__crashreporter_info__ = "Instrumented by Valgrind " VERSION;
            

            解决此问题的方法是添加以下行:

            #define __private_extern__ extern
            

            到以下文件:

            • coregrind/m_syscall.c
            • coregrind/m_syswrap/syswrap-darwin.c
            • coregrind/vg_preloaded.c

            最后,您需要祈祷不要出现其他错误:

            $ make
            $ make install
            

            【讨论】:

            • 我能够在 MacOS Mojave 10.14.13 上使用上述说明安装 valgrind,而无需对文件添加修复:coregrind/m_syscall.c、coregrind/m_syswrap/syswrap-darwin.c、coregrind /vg_preloaded.c
            • 要添加到此,您可能需要更改“/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk”以反映您的 sdk版本。就我而言,它是“MacOSX10.11.sdk”。因此,在我的情况下,路径是“/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk”。
            • 不幸的是,它对我不起作用。 Mac 操作系统 10.14.4。我最终得到了这个错误“架构 x86_64 的未定义符号:“_mach_msg_destroy”,引用自:__kernelrpc_mach_vm_allocate in libcoregrind-amd64-darwin.a(libcoregrind_amd64_darwin_a-mach_vmUser.o) .."
            • 我想补充一点,运行 ./autogen.sh 需要安装包“automake”。您可以通过以下方式做到这一点: brew install automake
            • 这无法在带有 Xcode 11.2.1 的 macOS 10.14.6 中编译。我收到错误"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/mach/task.defs", line 509: type 'task_exc_guard_behavior_t' not defined
            【解决方案9】:

            对于 macOS 来说不是一个合适的解决方案,但我暂时创建了一个 docker 映像。在为 macOS 安装 docker 后,这是如何启动 valgrind:

            cd </path/to/source/directory/where/you/want/run/valgrind/with>
            curl -O https://raw.githubusercontent.com/biocyberman/ValgrindDocker/master/startValgrind
            ./startValgrind # this will takes time for the first time, because it needs to fetch docker valgrind image
            # you will get a root command prompt inside the docker image. 
            # do what ever you want
            # type 'exit' to quit
            

            【讨论】:

              【解决方案10】:

              我也有同样的问题。看来 valgrind 与最新的 macOS(10.14 Mojave)不兼容。尝试以 High Sierra 方式 (https://www.gungorbudak.com/blog/2018/04/28/how-to-install-valgrind-on-macos-high-sierra/) 安装它并获得与您描述的相同的输出。我现在可以为您提供的唯一解决方案是使用虚拟机 (https://www.virtualbox.org/) 或使用 Docker (https://www.gungorbudak.com/blog/2018/06/13/memory-leak-testing-with-valgrind-on-macos-using-docker-containers/)。

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 2020-02-10
                • 2019-12-25
                • 1970-01-01
                • 1970-01-01
                • 2019-06-15
                • 1970-01-01
                • 2019-03-02
                • 2019-03-15
                相关资源
                最近更新 更多