80

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.

Ashishkel
  • 845
  • 11
  • 19
jaswanth
  • 1,021
  • 1
  • 7
  • 14

20 Answers20

91

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.

peterSO
  • 134,261
  • 26
  • 231
  • 232
  • 1
    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.` – jaswanth Apr 25 '17 at 04:03
  • I installed [libtools](http://gnuwin32.sourceforge.net/packages/libtool.htm) but its not working – jaswanth Apr 26 '17 at 07:02
  • jaswanth, check out the answer @Ashinkel has given. I did have the same problem, but that worked for me. – pkmelee337 May 30 '18 at 22:56
  • When downloading the TDM-GCC installer for Windows, use the x64 version. The 32-bit version did not solve the problem for me. – Kent Apr 12 '19 at 02:41
  • Installation of TDM-GCC [https://jmeubank.github.io/tdm-gcc/] works fine for me Windows 10 testing execution with fyne [https://fyne.io] – Camilo Caquimbo Aug 28 '20 at 04:18
70

If you are running Ubuntu do:

apt-get install build-essential

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

questionaire
  • 2,059
  • 1
  • 10
  • 24
mahima
  • 1,013
  • 7
  • 13
13

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.

ame
  • 407
  • 4
  • 17
  • 2
    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. – Bazzz Mar 17 '19 at 09:14
  • 1
    `C:\Program Files\Git\mingw64\bin` in my case, since I installed the Git client and it uses mingw64 – T1960CT Sep 08 '19 at 19:41
  • 2
    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. – lucsan Nov 10 '19 at 15:10
6

On window install http://tdm-gcc.tdragon.net/download, after installed it, you need to reset your PC. that all

Le Nguyen
  • 103
  • 1
  • 7
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 
Alexey Shevelyov
  • 836
  • 13
  • 20
3

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.

Ashishkel
  • 845
  • 11
  • 19
  • 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" – pkmelee337 May 30 '18 at 22:55
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/

vraj9845
  • 31
  • 2
3

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
Carson
  • 1,762
  • 1
  • 10
  • 23
2

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.
Suriyaa
  • 2,243
  • 2
  • 23
  • 45
  • 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? – Robert Snyder Oct 07 '18 at 03:31
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 ..."
greybeard
  • 2,015
  • 5
  • 20
  • 51
2

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
Yagiz Degirmenci
  • 5,473
  • 3
  • 18
  • 49
1

Kindly install the MINGW after GUI will automatically take.

http://mingw.org/wiki/Getting_Started

premnikf7
  • 25
  • 4
1
$ go env

check CGO_ENABLED if its 1 change it to 0 by

$export CGO_ENBLED=0 
0

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.

oasf
  • 1
  • 1
  • 3
0
  1. you need to download MingGW64
  2. put MingGW64 folder into your $PATH
  3. run go build xxx.go (with cgo library)
paulg
  • 96
  • 4
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.

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

0

On Windows, you can install gcc by Scoop:

scoop install gcc
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.

Arsham
  • 260
  • 4
  • 9
0

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.

Narayan Shrestha
  • 434
  • 4
  • 13