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
update Ok, I've got my answer. For those who are interested : https://groups.google.com/forum/#!topic/golang-dev/ckFZAZbnjzU
Short answer: yes. Long answer: yes, but there are a couple of things to be aware of, both on the Go side and the C side. A short introduction to creating shared C libraries in Go can be found here and a longer one here. (Found by searching Google for go dynamic library .)
Go to the Search window and type cmd, right click on Command Prompt and choose Run as an administrator option. Type the following command in the command window and hit Enter - regsvr32 <dllname>
As of Go 1.10, -buildmode=c-shared is now supported on Windows.
Release notes: https://golang.org/doc/go1.10#compiler
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.
go build -buildmode=c-archive github.com/user/ExportHello
====> will build ExportHello.a
, ExportHello.h
Take the functions built in ExportHello.a
and re-export in Hello2.c
gcc -shared -pthread -o Hello2.dll Hello2.c ExportHello.a -lWinMM -lntdll -lWS2_32
====> will generate Hello2.dll
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With