Building a dll with Go 1.7


Is there a way to build a dll against Go v1.7 under Windows ?

I tried a classic

go build -buildmode=shared main.go

but get

-buildmode=shared not supported on windows/amd64

Ok, I’ve got my answer. For those who are interested :!topic/golang-dev/ckFZAZbnjzU


As of Go 1.10, -buildmode=c-shared is now supported on Windows.

Release notes:

So now compiling to DLL is a one-liner:

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

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.

Answered By – Andrew Dolder

Answer Checked By – Marilyn (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.