golang1.83
只有linux下支持plugin方式
生成so
package main // // No C code needed. import "C" import ( "fmt" ) var V int func F() { fmt.Printf("Hello, number %d\n", V)
}
go build -buildmode=plugin main.go
调用so
package main import ( "plugin" ) func main() { p, err := plugin.Open("main.so") if err != nil { panic(err) } v, err := p.Lookup("V") if err != nil { panic(err) } f, err := p.Lookup("F") if err != nil { panic(err) } *v.(*int) = 7 f.(func())()
}
http://blog.csdn.net/andylau00j/article/details/53769446