exec: "gcc": executable file not found in %PATH% when trying go build

gcc (the GNU Compiler Collection) provides a C compiler. On Windows, install TDM-GCC. The github.com/miekg/pkcs11 package uses cgo. Cgo enables the creation of Go packages that call C code.


I also encountered this message, but in my case, it was missing gcc.exe. I used choco and installed mingw, and then it worked.

details:

  1. download choco
  2. choco install mingw -y
  3. check: gcc -v

1) Install .exe from > https://sourceforge.net/projects/mingw-w64/

1.2) ! use x86_64 architecture

2) Add C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin to PATH in User Variables and in System Variables. For me it works.

! To edit Path variable press Windows key, type 'path', choose 'Edit the system environment variables', click 'Environment Variables', find Path variable in System variables and in User variables then edit.


If you are running Ubuntu do:

apt-get install build-essential

This solved the problem. It installs the gcc/g++ compilers and libraries.