go 工具链目前[不支持编译 windows 下的动态连接库][1],不过[支持静态连接库][2]。
想要产生dll,能够这样 workaround ,参考 golang [issuse#11058][1]:python
pacman -S mingw-w64-x86_64-toolchain
(注意这里有个坑, msys64 根目录有两个 mingw64.*
文件会致使 pacman 安装失败,我是暴力重命名了冲突的文件。)go build -buildmode=c-archive -o libfoo.a foo.go
$ cat foo.def EXPORTS Sum
gcc -m64 -shared -o foo.dll foo.def libfoo.a -Wl,--allow-multiple-definition -static -lstdc++ -lwinmm -lntdll -lWs2_32
[1] https://github.com/golang/go/issues/11058
[2] https://github.com/golang/go/issues/13494
[3] http://msys2.github.io/
[4] https://lug.ustc.edu.cn/wiki/mirrors/help/msys2c++