Building a dll with Go 1.7

Stef picture Stef · Nov 13, 2016 · Viewed 26k times · Source

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

Answer

user7155193 picture user7155193 · Nov 14, 2016
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