In the past, building a DLL with Go on Windows required additional steps and workarounds. However, with the release of Go 1.10, this process has become much more straightforward.
Previously, attempting to build a DLL using the -buildmode=shared flag resulted in an error indicating that it was not supported on Windows.
As of Go 1.10, a new flag, -buildmode=c-shared, has been introduced that allows for the compilation of DLLs on Windows.
The updated syntax to build a DLL is:
go build -o helloworld.dll -buildmode=c-shared
Note that the headers generated by this process are primarily compatible with GCC. If your DLL exposes only C-types, however, this should not be a significant concern. It has been demonstrated that LoadLibrary can be used successfully in Visual Studio even without the headers.
The above is the detailed content of How Can I Easily Build a DLL in Go on Windows?. For more information, please follow other related articles on the PHP Chinese website!