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
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:
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.
====> will build
ExportHello.a
,ExportHello.h
Take the functions built in
ExportHello.a
and re-export inHello2.c
====> will generate
Hello2.dll
There is a project on github which shows how to create a DLL, based on, and thanks to user7155193's answer.
Basically you use GCC to build the DLL from golang generated .a and .h files.
First you make a simple Go file that exports a function (or more).
Compile it with:
Then you make a C program (goDLL.c) which will link in the .h and .a files generated above
Compile/link the DLL with GCC:
The goDLL.dll then can be loaded into another C program, a freepascal/lazarus program, or your program of choice.
The complete code with a lazarus/fpc project that loads the DLL is here: https://github.com/z505/goDLL