使用 Go 1.7 构建 dll [英] Building a dll with Go 1.7
问题描述
有没有办法在Windows下针对Go v1.7构建一个dll?
Is there a way to build a dll against Go v1.7 under Windows ?
我尝试了经典
go build -buildmode=shared main.go
但是得到
-buildmode=shared 不支持 windows/amd64
-buildmode=shared not supported on windows/amd64
更新好的,我有我的答案.对于那些有兴趣的人:https://groups.google.com/forum/#!topic/golang-dev/ckFZAZbnjzU
update Ok, I've got my answer. For those who are interested : https://groups.google.com/forum/#!topic/golang-dev/ckFZAZbnjzU
推荐答案
从 Go 1.10 开始,Windows 现在支持 -buildmode=c-shared.
As of Go 1.10, -buildmode=c-shared is now supported on Windows.
发行说明:https://golang.org/doc/go1.10#compiler
所以现在编译成 DLL 是单行的:
So now compiling to DLL is a one-liner:
go build -o helloworld.dll -buildmode=c-shared
我相信头文件只与 GCC 兼容.如果您只公开 C 类型,这应该不是什么大问题.我能够让 LoadLibrary 在没有标题的情况下在 Visual Studio 中工作.
I believe the headers are only compatible with GCC. If you're only exposing C-types, this should not be a big issue. I was able to get LoadLibrary to work in Visual Studio without the header.
这篇关于使用 Go 1.7 构建 dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!