从一个基本的测试程序。。。
package main
/*
#include <stdio.h>
static void test() {
printf("hello world");
}
*/
import "C"
func main() {
C.test();
}我做了"cgo hello_cgo.go“,然后得到:
_cgo_.o
_cgo_defun.c
_cgo_gotypes.go
hello_cgo.cgo1.go
hello_cgo.cgo2.c我如何从这里编译成一个可执行文件?
发布于 2010-05-07 10:05:27
尝试使用go生成文件。创建makefile,如下所示
# Makefile
CGOFILES=test.go
TARG=test
include $(GOROOT)/src/Make.$(GOARCH)
include $(GOROOT)/src/Make.pkg然后,运行make将生成文件_obj/test.a,您必须使用6l或类似的链接来链接该文件。
发布于 2013-03-28 04:41:14
Go1更新:
$ cat foo.go
package main
// #include <stdio.h>
// static void test() { printf("Hello, world\n"); }
import "C"
func main() {
C.test()
}
$ go build foo.go
$ ./foo
Hello, worldhttps://stackoverflow.com/questions/2785696
复制相似问题