Building a dll with Go 1.7

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

-buildmode=shared not supported on windows/amd64

update Ok, I've got my answer. For those who are interested : https://groups.google.com/forum/#!topic/golang-dev/ckFZAZbnjzU

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.

windows - Building a dll with Go 1.7, 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  DLL that can be called from any Windows executable or another DLL. These others (executables and DLLs) can be written in C, but don't have to be - they can be written in Go. We (Go executables we build) use system DLLs (produced by Microsoft) all the time.

go build -buildmode=c-archive github.com/user/ExportHello

====> will build ExportHello.a, ExportHello.h

Take the functions built in ExportHello.a and re-export in Hello2.c

gcc -shared -pthread -o Hello2.dll Hello2.c ExportHello.a -lWinMM -lntdll -lWS2_32

====> will generate Hello2.dll

Building a dll with Go 1.7, Building a dll with Go 1.7. Question. 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. Any new suggestions? I no longer have 1.8.6. I even went through the registry. I reinstalled 1.7.6 cleared out the typescript folder and reinstalled 1.7.6 which did add the pertinent files back into the directory but after doing a clean on the solution I get the COMPUTE_PATHS_ONLY.ts not found. I tried to rebuild and get the same thing.

There is a project on github which shows how to create a DLL, based on, and thanks to user7155193's answer.

Basically you use GCC to build the DLL from golang generated .a and .h files.

First you make a simple Go file that exports a function (or more).

package main

import "C"
import "fmt"

//export PrintBye
func PrintBye() {
    fmt.Println("From DLL: Bye!")
}

func main() {
    // Need a main function to make CGO compile package as C shared library
}

Compile it with:

go build -buildmode=c-archive exportgo.go

Then you make a C program (goDLL.c) which will link in the .h and .a files generated above

#include <stdio.h>
#include "exportgo.h"

// force gcc to link in go runtime (may be a better solution than this)
void dummy() {
    PrintBye();
}

int main() {

}

Compile/link the DLL with GCC:

gcc -shared -pthread -o goDLL.dll goDLL.c exportgo.a -lWinMM -lntdll -lWS2_32

The goDLL.dll then can be loaded into another C program, a freepascal/lazarus program, or your program of choice.

The complete code with a lazarus/fpc project that loads the DLL is here: https://github.com/z505/goDLL

go1.10 build c-shared for to windows dll · Issue #23052 · golang/go , Glad to see go1.10 support compiled dll, but the following questions (suggestions​): The export function has unnecessary entries; The output file  Unsubscribe from MJ Tube? Sign in to add this video to a playlist. Sign in to report inappropriate content. Sign in to make your opinion count. Sign in to make your opinion count. The interactive

z505/goDLL: how to create windows golang DLL and load , Current way of making a DLL: compile go code with regular go compiler and put that puts code into .a and .h files for you. These are just like C code  Unpack APR 1.7.0 source distribution in this directory (C:\tomcat-native-1.2.x ative\srclib\apr). Apply the apr-enable-ipv6.patch. Note that the patch will apply but depending on exactly which revision you are working with you may need to skip the first part of the patch and an offset will probably be required.

Building Applications and Components with Visual Basic .NET, Now it's time to go into more detail. Every managed Figure 1.7 provides a more realistic view of the actual assemblies used by a typical Visual Basic . The above trick will create a libssh2.dll that is statically linked with libvcruntime.lib instead of vcruntime.lib which means you do not need to have VCRUNTIME140.DLL or VCRUNTIME140D.DLL on your system.

Ogre 3D 1.7 Beginner's Guide, Otherwise, we can't build any application using Ogre 3D. use the debug libraries because they offer better debug support if something happens to go wrong. about Ogre 3D and tells our application to load OgreMain . dll or OgreMain_d.dll. Hey all, I've created a Patreon page! If you wish to help out the channel please go to https://www.patreon.com/thecod3r where you can support me and help to

Comments
  • -buildmode=shared is a Go shared library, which wouldn't make a DLL anyways. You most likely were looking for buildmode=c-shared, though that hasn't been worked on for windows yet, and you can follow issue #11058
  • Btw, Go 1.10 does support building windows DLLs since update in Oct 10, 2017. go build -buildmode=c-shared That single command will generate any DLL for Windows systems. refer to: go-review.googlesource.com/c/go/+/69091