1) GO源代码
[root@test129 test]# cat hello.go
package main
import "C"
//export Hello
func Hello() string {
return "Hello"
}
func main() {
}
}
2) 编译GO动态链接库
gobuild -v -x -buildmode=c-shared -o libhello.so
会生成libhello.h、libhello.so两个文件。
3) C源代码
[root@test129 test]# cat test.c
#include<stdio.h>
#include "libhello.h"
void main()
{
printf("%s in C\n", Hello());
}
4) 编译C可执行程序
gcc test.c -lhello -o test