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

24

153

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.

Rennold answered 24/4, 2017 at 5:3 Comment(7)
So what is your question?Gybe
go build command giving the above gcc error ... how can i solve itRennold
Do you have gcc installed?Gybe
no .. is it required ?Rennold
Well, yes of course.Howlyn
@jaswanth: Your error message is "gcc": executable file not found. That should be your first clue that "gcc" is required but not found.Depersonalize
fabric uses cgo, and cgo needs gcc.Symphonious
P
148

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.

Pavement answered 24/4, 2017 at 12:34 Comment(6)
tq it worked but getting different error now .\hyperledger\fabric\vendor\github.com\miekg\pkcs11\pkcs11.go:29:18: fatal error: ltdl.h: No such file or directory compilation terminated.Rennold
I installed libtools but its not workingRennold
jaswanth, check out the answer @Ashinkel has given. I did have the same problem, but that worked for me.Ozuna
When downloading the TDM-GCC installer for Windows, use the x64 version. The 32-bit version did not solve the problem for me.Sloganeer
Installation of TDM-GCC [jmeubank.github.io/tdm-gcc/] works fine for me Windows 10 testing execution with fyne [fyne.io]Seurat
If you are using VSCode, after installing TDM-GCC you will need to close VSCode and reopen it. This is needed so that the VScode terminal is updated and the gcc command can be found.Izzy
K
151

If you are running Ubuntu do:

apt-get install build-essential

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

Kiangsu answered 16/4, 2019 at 10:0 Comment(5)
use this command, when you are facing the issue in Ubuntu with sudoAlderman
If you are facing with dependencies when installing try ‘sudo aptitude install build-essential’Cheri
Which Ubuntu shell stores the path in a variable called %PATH%?Crosspurpose
Worth noting that build-essential is not required to build Go source code, so you might not need this until you install a dependency that needs it to buildPervade
The OP is using Windows!Piss
P
148

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.

Pavement answered 24/4, 2017 at 12:34 Comment(6)
tq it worked but getting different error now .\hyperledger\fabric\vendor\github.com\miekg\pkcs11\pkcs11.go:29:18: fatal error: ltdl.h: No such file or directory compilation terminated.Rennold
I installed libtools but its not workingRennold
jaswanth, check out the answer @Ashinkel has given. I did have the same problem, but that worked for me.Ozuna
When downloading the TDM-GCC installer for Windows, use the x64 version. The 32-bit version did not solve the problem for me.Sloganeer
Installation of TDM-GCC [jmeubank.github.io/tdm-gcc/] works fine for me Windows 10 testing execution with fyne [fyne.io]Seurat
If you are using VSCode, after installing TDM-GCC you will need to close VSCode and reopen it. This is needed so that the VScode terminal is updated and the gcc command can be found.Izzy
F
27

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
Flash answered 3/3, 2021 at 1:28 Comment(2)
Also works with scoop: scoop install mingwHacking
Quick question, why does this not work if you just install gcc directly with scoop (e.g. scoop install gcc)?Athiste
H
19

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.

Honewort answered 20/11, 2018 at 13:54 Comment(3)
This explanation is a little cryptic but I managed to solve the issue by reading well what is said here and "interpret" Alex's intentions: apply step 1.2 whilst installing the application in step 1, and only after that go to step 2.Symptomatology
C:\Program Files\Git\mingw64\bin in my case, since I installed the Git client and it uses mingw64Submissive
On Windows, once you have edited the PATH in System Environment Variables, remember you need to exit/kill any open command terminals you intend using, as they will not receive a PATH update.Geller
C
18

On Windows install https://jmeubank.github.io/tdm-gcc/, that is all.

Conquest answered 21/5, 2019 at 3:24 Comment(0)
P
15

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
Postboy answered 15/12, 2020 at 12:47 Comment(3)
Can you explain the intuition behind itPromiscuous
It contains several other packages that your OS might need including, g++, make, libc, libc-dev, gcc, etc.Postboy
this answer is savior!Sundial
H
9
$ go env

check CGO_ENABLED if its 1 change it to 0 by

$export CGO_ENABLED=0 
Homer answered 10/11, 2020 at 6:54 Comment(3)
You have a typo, it should be: export CGO_ENABLED=0 (with "A")Greatgrandaunt
inside a container?Saxecoburggotha
This ended up working for my specifc use case. Only difference was for windows needed to run go env -w GCO_ENABLED=0 on the CLIClubby
W
5

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.

Workingman answered 5/5, 2021 at 8:32 Comment(0)
D
4

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.

Demission answered 13/7, 2017 at 4:28 Comment(1)
Awesome! Thanks! If you use Visual Studio Code as windows editor you can add this to your settings with the following setting: "go.buildTags": "nopkcs11"Ozuna
M
4

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 
Minelayer answered 11/11, 2019 at 16:21 Comment(0)
C
4

For Ubuntu, what worked for me was to simply run:

sudo apt install gcc
Cicala answered 28/7, 2021 at 15:35 Comment(0)
T
4

just followed instructions from following and it solve my issue

https://code.visualstudio.com/docs/cpp/config-mingw

it ask to install Mingw-w64 via MSYS2

important command is pacman -S --needed base-devel mingw-w64-x86_64-toolchain then add C:\msys64\mingw64\bin to PATH

thanks

Typecast answered 18/6, 2022 at 11:6 Comment(0)
R
3

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/

Revivalist answered 30/12, 2020 at 3:13 Comment(1)
There is no need of dot at the end of the commandRema
C
3

On Amazon Linux 2:

  1. 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

  2. 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.

Censure answered 10/5, 2022 at 15:56 Comment(0)
R
2

on Ubuntu its very easy but on windows need to do it:

  1. download MinGW on http://www.mingw.org/
  2. install on basic package Gcc-g++ (see this image)
  3. add on environment Patch of windows variables.
  4. restart and continue with "go get ..."
Resale answered 18/3, 2020 at 16:25 Comment(0)
E
2

Just add this to your Dockerfile

RUN apk add alpine-sdk
Eurythmics answered 29/3, 2022 at 19:4 Comment(0)
C
1

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.

Coffle answered 24/4, 2017 at 8:35 Comment(0)
V
1

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.
Varanasi answered 28/4, 2018 at 16:12 Comment(1)
which path? I installed msys to c:\tools\msys64 and I think i'm supposed to use c:\tools\msys64\usr\bin to my PATH is that right?Miter
Q
1

Kindly install the MINGW after GUI will automatically take.

http://mingw.org/wiki/Getting_Started

Quenna answered 6/3, 2020 at 4:12 Comment(0)
W
1

On Windows, you can install gcc by Scoop:

scoop install gcc
Wickiup answered 10/4, 2021 at 12:51 Comment(1)
Scoop is my preferred method, as it does not require admin privileges, and uses current user directory, which seems like the cleanest solutionFishy
P
0
  1. you need to download MingGW64
  2. put MingGW64 folder into your $PATH
  3. run go build xxx.go (with cgo library)
Passage answered 15/8, 2017 at 1:17 Comment(0)
D
0

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.

Daff answered 14/4, 2018 at 6:21 Comment(0)
C
0

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

Calenture answered 9/1, 2020 at 10:22 Comment(0)
S
0

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.

Status answered 1/5, 2021 at 4:33 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.