【问题标题】:Installing the Boehm GC on OS X在 OS X 上安装 Boehm GC
【发布时间】:2020-11-05 13:33:55
【问题描述】:

我想在 MacOS 上安装 Boehm garbage collector 垃圾收集器。我查看了this 指南,但没有帮助;调用 brew install libgc 什么也没做。这是我尝试运行的示例代码:

#include <gc/gc.h>

int main() {
    void* eight_bytes = GC_MALLOC(8);
}

很遗憾,我收到了这个错误:

Undefined symbols for architecture x86_64:
  "_GC_malloc", referenced from:
      _main in boehm_invocation-369838.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

有谁知道无需从源代码构建即可安装此 GC 的好方法吗?

【问题讨论】:

    标签: c garbage-collection clang ld boehm-gc


    【解决方案1】:

    当我像您一样在 mac 上安装 libgc 时,文件已安装到 /usr/local/Cellar/bdw-gc/。然后,当需要编译我的代码时,我必须运行:

    $ LIBGC=/usr/local/Cellar/bdw-gc/VERSION/
    $ gcc ... -I$LIBGC/include/ ... $LIBGC/lib/libgc.a other.a ...
    

    当您安装 libgc 时,它不会包含在您的系统路径中。您需要显式添加它。

    也在我使用的代码中:

    #include "gc.h"
    

    而不是&lt;gc/gc.h&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-13
      • 2013-12-21
      • 2010-10-28
      • 2013-08-23
      • 2014-12-14
      • 2011-10-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多