Microsoft Windows

For Cgo to function on Windows, you'll need to have the gcc (or compatible) compiler installed. If Visual Studio is already installed, then you may have a C compiler. For those who don't, this section steps through configuring a build environment on the command line. The easiest way to get up and running (in my experience) is to download and install MSYS2 (a software distribution) and build a platform for Windows. Using MSYS2, we can install the mingw-w64 packages, which provide an updated distribution of the gcc for Windows project named mingw.

Download the installer from www.msys2.org/—choose either the 32 bit (i686) or 64 bit (x86_64) versions, depending on your computer architecture. Once downloaded, run this installer, which will download the basic packages to your computer, including the package manager (pacman). Once complete, it'll launch the MSYS Command Prompt, which will be used for any projects requiring Cgo. You'll need to update the PATH environment variable to use the existing Go and Git installations:

An MSYS console provides access to many additional packages

Once you have the command line set up, the package manager is used to install a C compiler and toolchain as well as pkg-config (which is used by Cgo to find packages):

pacman -S mingw-w64-x86_64-toolchain mingw-w64-x86_64-pkg-config

Once complete, you'll be able to execute gcc and pkg-config from the MSYS command line—these tools are essential for a working Cgo setup. The following output may display an error, but it shows that the tools are found:

Pacman on MSYS provides the packages we need
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.142.85