CGO inside Windows

What is CGO?

CGO lets Go packages call C code

Installing MSYS2

  • Download installer from (current it’s msys2-x86_64-20200903.exe)
  • After install, inside MSYS terminal, using pacman, install gcc
pacman -S \
 mingw-w64-x86_64-binutils \
 mingw-w64-x86_64-crt-git \
 mingw-w64-x86_64-gcc \
 mingw-w64-x86_64-gcc-libs \
 mingw-w64-x86_64-gdb  \
 mingw-w64-x86_64-headers-git \
 mingw-w64-x86_64-libmangle-git   \
 mingw-w64-x86_64-libwinpthread-git \
 mingw-w64-x86_64-make \
 mingw-w64-x86_64-pkg-config \
 mingw-w64-x86_64-tools-git \
 mingw-w64-x86_64-winpthreads-git \
  • now, configure bash initialization
# inside: ~/.bashrc

alias ll="ls -la --color"

export PATH=/s/go/bin:$PATH
export GOPATH=/w/work/go

Configure Windows Terminal

As explained in official guide…

 "guid": "{17da3cac-b318-431e-8a3e-7fcdefe6d114}",
 "name": "MINGW64 / MSYS2",
 "commandline": "S:/msys64/msys2_shell.cmd -defterm -here -no-start -mingw64",
 //"startingDirectory": "C:/msys64/home/%USERNAME%",
 "startingDirectory": "W:/work",
 "icon": "S:/msys64/mingw64.ico",
 "fontSize": 12,
 "colorScheme": "GitBash"
 "guid": "{2d51fdc4-a03b-4efe-81bc-722b7f6f3820}",
 "name": "MINGW32 / MSYS2",
 "commandline": "S:/msys64/msys2_shell.cmd -defterm -here -no-start -mingw32",
 // "startingDirectory": "C:/msys64/home/%USERNAME%",
 "startingDirectory": "W:/work",
 "icon": "S:/msys64/mingw32.ico",
 "fontFace": "Lucida Console",
 "fontSize": 12
 "guid": "{71160544-14d8-4194-af25-d05feeac7233}",
 "name": "MSYS / MSYS2",
 "commandline": "S:/msys64/msys2_shell.cmd -defterm -here -no-start -msys",
 // "startingDirectory": "C:/msys64/home/%USERNAME%",
 "startingDirectory": "W:/work",
 "icon": "S:/msys64/msys2.ico",
 "fontFace": "Lucida Console",
 "fontSize": 14


go get
go install

Windows Terminal Git Bash

How to add Git Bash into Windows Terminal

Inside Windows Terminal, press CTRL+, to start editing “settings.json”

   "profiles": {
      "list": [
            "guid": "{f9c3b687-50b7-4b13-b312-c28e955ed7d3}",
            "hidden": false,
            "name": "Git Bash",
            "commandline": "S:/app/Git/usr/bin/bash.exe -i -l",
            "startingDirectory": "W:/work",
            "icon": "S:/app/Git/mingw64/share/git/git-for-windows.ico",
            "snapOnInput": true,
            "closeOnExit": true,
            "colorScheme": "GitBash",
            "fontFace": "Consolas",
            "fontSize": 14

After this, add a custom color scheme named “GitBash”

"schemes": [
      "name": "GitBash",
      "background": "#FFFFF0",
      "foreground": "#404040",
      "black": "#0C0C0C",
      "blue": "#6060ff",
      "brightBlack": "#767676",
      "brightBlue": "#3B78FF",
      "brightCyan": "#61D6D6",
      "brightGreen": "#16C60C",
      "brightPurple": "#B4009E",
      "brightRed": "#E74856",
      "brightWhite": "#F2F2F2",
      "brightYellow": "#F9F1A5",
      "cyan": "#3A96DD",
      "green": "#00a400",
      "purple": "#bf00bf",
      "red": "#bf0000",
      "white": "#ffffff",
      "yellow": "#bfbf00",
      "grey": "#bfbfbf"


Windows 10 permissions

RunAs Administrator:

REM Backup permissions of WindowsApps
icacls "%ProgramFiles%\WindowsApps" /save WindowsApps.acl

REM change owner to copy directory (it's a LOT of files!!!)
takeown /F “C:\Program Files\WindowsApps” /A /R

robocopy "c:\Program Files" s:\C_ProgramFiles /COPYALL /MIR /LOG:robocopy.txt /ZB /DCOPY:T /V /TEE

REM restore permissions
icacls "%ProgramFiles%" /restore WindowsApps.acl
RunAs Administrator:

cd some_directory
icacls * /t /q /c /reset
takeown /R /F *
icacls * /t /grant Everyone:F
cd ..
REM List all symbolic links and directory junctions
DIR /AL /S C:\

Junctions vs Directory symbolic link

icacls reference