can't find import: "C"

475 views
Skip to first unread message

notedit

unread,
Dec 2, 2011, 2:56:02 AM12/2/11
to golang-nuts
today i try the cgo on my mba, i try the rand.go example on
http://blog.golang.org/2011/03/c-go-cgo.html

but i came to an error.

when i make, the error is

6g -p rand -o _go_.6 test_rand.go
test_rand.go:8: can't find import: "C"
make: *** [_go_.6] Error 1


this is my evn:

notedit@localhost:~/study/golang/gotest$ 6g -V
6g version weekly.2011-11-18 10582

notedit@localhost:~/study/golang/gotest$ cat test_rand.go
package rand

/*
#include <stdlib.h>
*/

import (
"C"
)

func Random() int {
return int(C.random())
}

func Seed(i int) {
C.srandom(C.uint(i))
}


notedit@localhost:~/study/golang/gotest$ cat Makefile
include $(GOROOT)/src/Make.inc

TARG=rand
GOFILES=\
test_rand.go\

include $(GOROOT)/src/Make.pkg


unread,
Dec 2, 2011, 3:23:51 AM12/2/11
to golang-nuts
On Dec 2, 8:56 am, notedit <note...@gmail.com> wrote:
> notedit@localhost:~/study/golang/gotest$ cat Makefile
> include $(GOROOT)/src/Make.inc
>
> TARG=rand
> GOFILES=\
>                 test_rand.go\
>
> include $(GOROOT)/src/Make.pkg

CGOFILES=\
                test_rand.go\

6355...@qq.com

unread,
Dec 2, 2011, 3:42:06 AM12/2/11
to golang-nuts
the blog post says:
"The comment must be immediately before the line that imports "C",
without any intervening blank lines, just like a documentation
comment."

notedit <note...@gmail.com> wrote:
> today i try the cgo on my mba,  i try the rand.go  example onhttp://blog.golang.org/2011/03/c-go-cgo.html

Reply all
Reply to author
Forward
0 new messages