运行简单的cgo文件时遇到错误。

huangapple go评论87阅读模式
英文:

Error encountered running simple cgo file

问题

我正在尝试测试cgo代码。

package main

// #include <stdlib.h>

import (
	"C"
	"fmt"
)

func main() {
	fmt.Printf("test %d\n", int(C.random()))
}

请检查最后的错误。出了什么问题?

英文:

I'm trying to test cgo code.

package main

// #include &lt;stdlib.h&gt;

import (
	&quot;C&quot;
	&quot;fmt&quot;
)

func main() {
	fmt.Printf(&quot;test %d\n&quot;, int(C.random()))
}

D:\Dev\Go\src&gt;go version 
go version go1.3 windows/amd64
 
D:\Dev\Go\src&gt;go env 
set GOARCH=amd64 
set GOBIN= 
set GOCHAR=6 
set GOEXE=.exe 
set GOHOSTARCH=amd64 
set GOHOSTOS=windows 
set GOOS=windows
set GOPATH=D:\\Dev\\Go 
set GORACE= 
set GOROOT=c:\go 
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64 
set CC=gcc 
set GOGCCFLAGS=-m64-mthreads -fmessage-length=0 
set CXX=g++ 
set CGO_ENABLED=1

D:\Dev\Go\src&gt;go run test_binding.go
# runtime/cgo C:\Users\hyoon\AppData\Local\Temp\go-build779392087\runtime\cgo\_obj\_cgo_defun.c:7 6c: No such file  or directory: runtime.h

please check the last error. what's wrong?

答案1

得分: 1

这个程序的输出是什么?

package main

/*
#include <stdlib.h>
*/
import "C"

import (
	"fmt"
)

func main() {
	fmt.Printf("test %d\n", int(C.rand()))
}
英文:

What output do you get from this program?

package main

/*
#include &lt;stdlib.h&gt;
*/
import &quot;C&quot;

import (
	&quot;fmt&quot;
)

func main() {
	fmt.Printf(&quot;test %d\n&quot;, int(C.rand()))
}

huangapple
  • 本文由 发表于 2015年3月24日 10:55:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/29224244.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定