1.Go代码
package main

import "C"

//export SayHello
func SayHello() {
    println("Hello from Go!")
}

func main() {}
//export
2. 编译成动态库

2.1 windows

go build -buildmode=c-shared -o mylib.dll

2.2linux

go build -buildmode=c-shared -o mylib.so
动态文件.h
3. 编写c语言测试文件
#include <stdio.h>
#include "mylib.h"

int main() {
  SayHello();

  return 0;
}
gcc test.c mylib.dll -o test.exetest.exe