Golang’s CGO calls GCC to compile C code. The GCC toolchain is handy on Linux, but not on Windows. Golang, the vc used on Windows, is not supported. So what if there is such a need? Using MinGW.
Packages on Linux cannot be compiled directly on Windows, except with Cygwin or MSYS. (Then there are a lot of dependencies to resolve.) Project to cGO call is ImageMagick, can directly find the VC compiled library, save a lot of trouble.
Note that there are 32 and 64 bits of MinGW (MINGW-W64). (32-bit GCC’s default compilation parameters are compatible with 386cpus of decades ago, so ditch the 32-bit if you can… It’s hard to shake off that old historical baggage.)
The next issue is that the format of the VC library is.lib and.a of GCC are different, the old version of MinGW required the reimp tool to convert the lib into A, the new version is directly compatible with the lib format, reimp has also been removed. CORE_RL_MagickCore_. Lib -> libcore.a CORE_RL_MagickWand_. Lib -> libwand_.
Set CGO_LDFLAGS to -l “{lib path}” -lcore-lWAND Remember to add the build parameter no_pkgconfig defined in the ImageMagick SDK to mask calls to pkgConfig. Go install -tags no_pkgconfig.
Because go has a compilation cache, i.e. $GOPATH/ PKG, as long as the CGO part of the code does not change, there is no need to add this part of the parameter. So if you want to use CGO, it is necessary to make a thin wrapper like the ImageMagick SDK and convert the C function into the GO function.