1. 实现方式与语法形式
基本方式:将 Go 程序编译成 DLL 供 C# 调用。
1.1 Go代码
注意:代码中 export 的注释是定义的入口描述不能省略
package mainimport "C"import "fmt"func main() {
fmt.Println(Test())}var _count = 0//Test ://export Testfunc Test() int {
_count++ return _count}
在 LiteIDE 中将编译配置的 BUILDARGS
自定义值为 --buildmode=c-shared -o Test.dll
,从而形成以下编译语句。
go build --buildmode=c-shared -o Test.dll
1.2 C# 代码
[DllImport("Test.dll", EntryPoint = "Test")]extern static int Test();
2. Windows 下编译依赖的环境
生成 DLL 依赖于 gcc,没有 gcc 环境时&#x