Building DLLs with Go 1.7 Under Windows
While trying to compile a DLL using Go 1.7 on Windows, you may encounter the error message "-buildmode=shared not supported on windows/amd64". This is because the -buildmode=shared flag is not available for Windows systems in Go versions prior to 1.10.
Solution in Go 1.10 and Later
With the release of Go 1.10, the -buildmode=c-shared flag has been introduced, allowing for DLL compilation on Windows. To build a DLL, simply use the following command:
go build -o helloworld.dll -buildmode=c-shared
Header Compatibility
The headers generated by Go are primarily compatible with GCC. However, if your DLL exposes only C-type data, this should not pose a significant issue. For instance, LoadLibrary can be used in Visual Studio without the header.
Legacy Solution
If you need to build DLLs with Go versions prior to 1.10, you can refer to the discussion thread on the Go Developer Forum linked in the original post for alternative solutions.
The above is the detailed content of How Can I Build DLLs with Go on Windows?. For more information, please follow other related articles on the PHP Chinese website!