Home >Backend Development >Golang >Can Go 1.7 Compile to a DLL on Windows?

Can Go 1.7 Compile to a DLL on Windows?

Linda Hamilton
Linda HamiltonOriginal
2024-12-13 15:31:17318browse

Can Go 1.7 Compile to a DLL on Windows?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn