cgo - 在 MacOSX 中找不到 'runtime.h' 文件

cgo - 'runtime.h' file not found in MacOSX

我正在尝试执行提到的 cgo 程序 here

    package main

    /*
    #include "runtime.h"

    int goId() {
            return g->goid;
    }
    */
    import "C"
    import "fmt"

    func main() {
     x := C.goId()
     fmt.Printf("Id - %d", x)
    }

在 运行 上面的程序中,我收到以下错误:-

jab-MacBook-Pro-4:src debraj$ go build gid.go
# command-line-arguments
./gid.go:4:10: fatal error: 'runtime.h' file not found
#include "runtime.h"
         ^
1 error generated.

如果我将 header 更改为如下所示:-

#include <objc/runtime.h>

然后它给我以下错误:-

jab-MacBook-Pro-4:src debraj$ go build gid.go
# command-line-arguments
./gid.go:7:9: error: use of undeclared identifier 'g'
        return g->goid;
               ^
1 error generated.

环境

谁能告诉我如何在 MacOSX 中运行上述程序?

golang-nuts 中所述,从 Go 1.5 开始这是不可能的

That's not a cgo program there, but a Go program, which uses the gc compiler's affinity to compile C programs into the resulting binary.

But since Go 1.5.0, that C backend is removed (the last version is 1.4.2), so that side effect has vanished.