exec: "gcc": executable file not found in %PATH% when trying go build
WindowsGoBuildHyperledger FabricCgoWindows Problem Overview
I am using Windows 10. When I tried to build Chaincode it reported this error
# github.com/hyperledger/fabric/vendor/github.com/miekg/pkcs11
exec: "gcc": executable file not found in %PATH%
My chaincode imports:
import (
"fmt"
"strconv"
"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer"
)
It's running fine in Docker.
Windows Solutions
Solution 1 - Windows
If you are running Ubuntu do:
apt-get install build-essential
This solved the problem. It installs the gcc/g++ compilers and libraries.
Solution 2 - Windows
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.
Solution 3 - Windows
- Install
.exe
from > https://sourceforge.net/projects/mingw-w64/
1.2) ! use x86_64
architecture
- Add
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin
toPATH
inUser Variables
and inSystem 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.
Solution 4 - Windows
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:
- download choco
choco install mingw -y
- check:
gcc -v
Solution 5 - Windows
If you are using an alpine based image with your Dockerfile
Install build-base
which will be met with your requirements.
apk add build-base
Solution 6 - Windows
On Windows install http://tdm-gcc.tdragon.net/download, that is all.
Solution 7 - Windows
The proper explanations why go build does not work for hyperledger in Windows environment are given as other answers. For your compilation purposes, just to make it work without installing anything extra, you can try the following
go build --tags nopkcs11
It worked for me. I hope same works for you too.
Solution 8 - Windows
You can try - this is not a solution but a temp workaround
cgo_enabled=0 go build
Once you install gcc - and make sure %PATH has a way to find it (gcc.exe) - this should go away.
Also running this one will ensure the cgo_enabled variable will stay this way as long as terminal is open. That way you don't have to prefix it each time you do a build.
export cgo_enabled=0 go build
Solution 9 - Windows
For my case : os: windows 10
command:
choco install mingw
install choco if not installed: Link: https://www.liquidweb.com/kb/how-to-install-chocolatey-on-windows/
worked for me.
Solution 10 - Windows
Instruction to fix the "exec: “gcc”: executable file not found in %PATH%" error with MSYS2:
- Download MSYS2.
- Put MSYS2 folder into your $PATH.
- Start the MSYS2 command line program.
- Run this command:
pacman -S gcc
.
Solution 11 - Windows
on Ubuntu its very easy but on windows need to do it:
- download MinGW on http://www.mingw.org/
- install on basic package Gcc-g++ (see this image)
- add on environment Patch of windows variables.
- restart and continue with "go get ..."
Solution 12 - Windows
$ go env
check CGO_ENABLED if its 1 change it to 0 by
$export CGO_ENABLED=0
Solution 13 - Windows
If you are running Ubuntu do:
sudo apt-get update
sudo apt-get install build-essential.
If the above commands do not work do:
sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) main universe"
The main component contains applications that are free software, can be freely redistributed and are fully supported by the Ubuntu team. & The universe component is a snapshot of the free, open-source, and Linux world.
Then install package by following command in terminal:
sudo apt-get update
sudo apt-get install build-essential.
For more info click here: https://itectec.com/ubuntu/ubuntu-problem-installing-build-essential-on-14-04-1-lts-duplicate/
Solution 14 - Windows
For Ubuntu, what worked for me was to simply run:
sudo apt install gcc
Solution 15 - Windows
gcc should not be necessary, unless you are cross compiling for a non-windows platform, or use cgo. If you still need gcc, however, you should install MinGW, which provides a gcc port for Windows (Cygwin and msys should also work, although I have never actually tested this).
Edit: I see from your error message now, that it is a dependency that requires gcc. If you didn't already know this, gcc is a c/c++ compiler, and in this case it is probably needed to compile c source files included by a dependency or sub-dependency.
Solution 16 - Windows
Kindly install the MINGW after GUI will automatically take.
Solution 17 - Windows
- you need to download MingGW64
- put MingGW64 folder into your $PATH
- run go build xxx.go (with cgo library)
Solution 18 - Windows
Hi jaswanth the main problem is that you haven't register your %GO_HOME%\pkg\tool\windows_amd64 to yuour Environment Path. %GO_HOME% is the repository where you install your go at the first time.
Solution 19 - Windows
same as other, just install tdm-gcc, but you can use its terminal, "MinGW", you can access it from start menu folder tdm-gcc, after start, browse to your project, and run it again
Solution 20 - Windows
On Windows, you can install gcc by Scoop:
scoop install gcc
Solution 21 - Windows
I'm a Windows user and I downloaded tdm-gcc (MinGW-w64 based) from the link below:
https://jmeubank.github.io/tdm-gcc/
After installation, it made a folder named "TDM-GCC-64".
I added "C:\TDM-GCC-64\bin" to my PATH, And it fixed my problem.
Solution 22 - Windows
Just add this to your Dockerfile
RUN apk add alpine-sdk
Solution 23 - Windows
On Amazon Linux 2:
-
Install go
wget https://go.dev/dl/go1.18.1.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.18.1.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
-
Install gcc
sudo yum groupinstall "Development Tools"
I recommend using the package group, even though it can be done without it, because groupinstall gives you the necessary packages to compile software on Amazon Linux and Redhat, CentOS for that matter.