如何使libgc在Mac OS X中工作



我一定错过了什么。即使是使用 libgc 的最简单的测试程序也会失败。有什么线索吗?

$ cat test.c 
#include <gc/gc.h>
int main(void)
{
    char *s;
    s = GC_MALLOC(1);
    return 0;
}
$ cc -ansi -pedantic -Wall -I/opt/local/include -L/opt/local/lib -o test test.c -lgc
$ ./test
Segmentation fault

我使用的是随 macports 一起安装的 libgc 版本 1。

显然我需要调用GC_INIT才能使libgc在Mac OS X上运行,所以我的测试程序将是:

#include <gc/gc.h>
int main(void)
{
    char *s;
    GC_INIT();
    s = GC_MALLOC(1);
    return 0;
}

最新更新