windows exec: "gcc": 尝试 go build 时在 %PATH% 中找不到可执行文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43580131/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:51:58  来源:igfitidea点击:

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

windowsgobuildhyperledger-fabriccgo

提问by jaswanth

I am using Windows 10. When I tried to build Chaincodeit reported this error

我使用的是 Windows 10。当我尝试构建Chaincode 时,它报告了这个错误

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

它在Docker 中运行良好。

回答by peterSO

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

gcc(GNU Compiler Collection)提供了一个 C 编译器。在 Windows 上,安装TDM-GCC。该github.com/miekg/pkcs11包使用cgo。Cgo 支持创建调用 C 代码的 Go 包。

回答by mahima

If you are running Ubuntu do:

如果您正在运行 Ubuntu,请执行以下操作:

apt-get install build-essential

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

这解决了问题。它安装 gcc/g++ 编译器和库。

回答by Alex Chaliy

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

1).exe从 > https://sourceforge.net/projects/mingw-w64/安装

1.2) ! use x86_64architecture

1.2)!使用x86_64架构

2) Add C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\binto PATHin User Variablesand in System Variables. For me it works.

2) 添加C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\binPATHinUser Variables和 in System Variables。对我来说它有效。

! To edit Pathvariable press Windowskey, type 'path', choose 'Edit the system environment variables', click 'Environment Variables', find Pathvariable in System variablesand in User variablesthen edit.

!要编辑Path变量按Windows键,输入“路径”,选择“编辑系统环境变量”,单击“环境变量”,找到Path变量System variablesUser variables然后编辑。

回答by Le Nguyen

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

在窗口安装http://tdm-gcc.tdragon.net/download,安装后,您需要重置您的电脑。这一切

回答by Ashishkel

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 不适用于 Windows 环境中的超级账本的正确解释。为了您的编译目的,只是为了在不安装任何额外内容的情况下使其工作,您可以尝试以下操作

go build --tags nopkcs11

It worked for me. I hope same works for you too.

它对我有用。我希望同样适用于你。

回答by Alexey Shevelyov

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.

一旦你安装了 gcc - 并确保 %PATH 有办法找到它(gcc.exe) - 这应该会消失。

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.

同时运行这个将确保只要终端打开, cgo_enabled 变量就会保持这种状态。这样你就不必在每次构建时都给它加上前缀。

export cgo_enabled=0 go build 

回答by premnikf7

Kindly install the MINGW after GUI will automatically take.

请安装 MINGW 后 GUI 会自动获取。

http://mingw.org/wiki/Getting_Started

http://mingw.org/wiki/Getting_Started

回答by Romen Rodríguez

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

在 Ubuntu 上很容易,但在 Windows 上需要这样做:

  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 ..."
  1. http://www.mingw.org/上下载 MinGW
  2. 安装在基本包 Gcc-g++ 上(见这个图像
  3. 添加 Windows 变量的环境补丁。
  4. 重新启动并继续“go get ...”

回答by Suriyaa

Instruction to fix the "exec: “gcc”: executable file not found in %PATH%" error with MSYS2:

使用 MSYS2修复“ exec:”gcc”:在 %PATH% 中找不到可执行文件”错误的说明:

  • Download MSYS2.
  • Put MSYS2 folder into your $PATH.
  • Start the MSYS2 command line program.
  • Run this command: pacman -S gcc.
  • 下载 MSYS2。
  • 将 MSYS2 文件夹放入 $PATH。
  • 启动 MSYS2 命令行程序。
  • 运行此命令:pacman -S gcc

回答by oasf

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

gcc 不是必需的,除非您是为非 Windows 平台交叉编译,或者使用 cgo。但是,如果您仍然需要 gcc,则应该安装 MinGW,它为 Windows 提供了 gcc 端口(Cygwin 和 msys 也应该可以工作,尽管我从未实际测试过)。

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.

编辑:我现在从您的错误消息中看到,它是一个需要 gcc 的依赖项。如果您还不知道这一点,gcc 是 ac/c++ 编译器,在这种情况下,可能需要编译包含在依赖项或子依赖项中的 c 源文件。