项目中项目基本是golang,因为以前的一个库不太好用golang重写,所以只能使用cgo来调用,稍微记录一下
看使用文档
重要的事情说多遍都不为过,一定要仔细看文档:
https://github.com/golang/go/wiki/cgo
注意cgo的注释和 import “C”之间不能有空行!!!
Note that there must be no blank lines in between the cgo comment and the import statement.
package main
/*
#include <stdio.h>
int test() {
return 2016;
}
*/
import "C"
import "fmt"
func main() {
fmt.Println(C.test())
}
编译的时候出错: