Compiling Go Code to a DLL in Windows
The question arises regarding the possibility of compiling Go code into a DLL on Windows using Go version 1.7. Upon attempting to use the typical command go build -buildmode=shared main.go, the error message "-buildmode=shared not supported on windows/amd64" appears.
Solution
As of Go 1.10, the -buildmode=c-shared option is now supported on Windows platforms. This means compiling a DLL in Go has become a straightforward process, requiring only one command:
go build -o helloworld.dll -buildmode=c-shared
It should be noted that any exported types must be C-compatible for this process to succeed. Additionally, while Windows headers are only fully compatible with GCC, calling LoadLibrary in Visual Studio may be possible even without them if only C-types are exposed.
The above is the detailed content of Can Go 1.7 Compile to a DLL on Windows?. For more information, please follow other related articles on the PHP Chinese website!