Building a dll with Go 1.7

前端 未结 3 1801
生来不讨喜
生来不讨喜 2020-12-07 23:39

Is there a way to build a dll against Go v1.7 under Windows ?

I tried a classic

go build -buildmode=shared main.go

but get

3条回答
  •  無奈伤痛
    2020-12-08 00:00

    As of Go 1.10, -buildmode=c-shared is now supported on Windows.

    Release notes: https://golang.org/doc/go1.10#compiler

    So now compiling to DLL is a one-liner:

    go build -o helloworld.dll -buildmode=c-shared
    

    I believe the headers are only compatible with GCC. If you're only exposing C-types, this should not be a big issue. I was able to get LoadLibrary to work in Visual Studio without the header.

提交回复
热议问题