Home > Backend Development > Golang > How Can I Build DLLs with Go on Windows?

How Can I Build DLLs with Go on Windows?

Mary-Kate Olsen
Release: 2024-12-13 15:54:10
Original
156 people have browsed it

How Can I Build DLLs with Go on Windows?

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
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template