Go toolchain currently [does not support compiling dynamic-link libraries under Windows][1], but [supports static-link libraries][2]

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

The go toolchain currently [does not support the compilation of dynamic link libraries under Windows][1], but [supports static link library][2].
To generate a DLL, this can be workaround, refer to Golang [issuse#11058][1]:



      • First I had to install a GCC development environment under Windows, and I used [msys2][3].

      • Need to configure a quick source, I use [China University of Science and Technology source][4].

      • Installing the GCC toolchain: pacman -S mingw-w64-x86_64-toolchain (note there is a pit, Msys64 root directory has two mingw64.* files will cause the Pacman installation to fail, I was violently renamed the conflicting files.) )

      • To compile a static link library:go build -buildmode=c-archive -o libfoo.a foo.go

      • Prepare to export the symbol definition file, Sum is the name of the function that needs to be exported:
        $ cat foo.defEXPORTS    Sum

      • Use GCC to turn a static link library into a dynamic link library:gcc -m64 -shared -o foo.dll foo.def libfoo.a -Wl,--allow-multiple-definition -static -lstdc++ -lwinmm -lntdll -lWs2_32

[1] https://github.com/golang/go/issues/11058
[2] https://github.com/golang/go/issues/13494
[3] http://msys2.github.io/
[4] Https://lug.ustc.edu.cn/wiki/mirrors/help/msys2

Go from 1.5 onwards support compiled C-Call dynamic link library

Shared Librariesgo 1.5 can produce Go GKFX libraries that can is consumed by Go programs. Build the standard library as shared libraries:$ goInstall-buildmode=SharedStdBuild A"Hello, World" program, links against theshared libraries:$ go build-linkshared hello.go$ ls-l hello-rwxr-xr-x 1 ADG ADG 13926 may 
              
               02:
               HelloGo 1.5 can also build Go programs as C archive files (for Static Lin King) or shared libraries (fordynamic linking), that can is consumed by C programs.   
              

For more detailed usage, refer to
Golang.org/s/execmodes

Try buildmode=c-archive compile to. A. h package for C language use: But not supported x86 only support AMD64

$ go install-buildmode=shared STD
-buildmode=shared not supported on windows/386

Windows not supported ...

https://gocn.io/question/205

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.