2016-12-15 84 views
-1
沒有發現「runtime.h」文件

我試圖執行CGO程序提到hereCGO - 在MacOSX上

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. 

如果我改變標題是象下面這樣: -

#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 - 10.11.6
  • 圍棋 - 1.7.3

有人可以讓我知道我怎麼可以運行MacOSX的上述計劃?

+1

它是不存在的,因爲運行時不再用C寫的 – JimB

+0

你能張貼此作爲一個答案讓我能接受? – tuk

回答

0

golang-nuts討論,這是不可能的,因爲圍棋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.