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

huangapple go评论104阅读模式
英文:

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

问题

我正在使用Windows 10。当我尝试构建Chaincode时,报告了以下错误:

# github.com/hyperledger/fabric/vendor/github.com/miekg/pkcs11 
exec: "gcc": 在%PATH%中找不到可执行文件

我的Chaincode导入了以下包:

import (
	"fmt"
	"strconv"

	"github.com/hyperledger/fabric/core/chaincode/shim"
	pb "github.com/hyperledger/fabric/protos/peer"
)

在Docker中它可以正常运行。

英文:

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.

答案1

得分: 145

[gcc](GNU编译器套件)提供了一个C编译器。在Windows上,安装[TDM-GCC]。github.com/miekg/pkcs11包使用[cgo]。Cgo使得可以创建调用C代码的Go包。

英文:

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.

答案2

得分: 142

如果你正在运行Ubuntu操作系统,可以执行以下命令来解决问题:

apt-get install build-essential

这将安装gcc/g++编译器和相关的库文件。

英文:

If you are running Ubuntu do:

apt-get install build-essential

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

答案3

得分: 26

我也遇到了这个问题,但在我的情况下,缺少了gcc.exe。我使用choco安装了mingw,然后问题就解决了。

具体步骤如下:

  1. 下载choco
  2. 运行choco install mingw -y
  3. 检查:gcc -v
英文:

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

答案4

得分: 19

1)从以下网址下载.exe文件:https://sourceforge.net/projects/mingw-w64/
1.2)请使用x86_64架构。
2)将C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin添加到用户变量系统变量PATH中。对我来说有效。
!要编辑Path变量,请按下Windows键,输入'path',选择'编辑系统环境变量',点击'环境变量',在系统变量用户变量中找到Path变量,然后进行编辑。

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

1.2) ! use x86_64 architecture

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

答案5

得分: 16

在Windows上安装https://jmeubank.github.io/tdm-gcc/,就是这样。

英文:

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

答案6

得分: 15

如果您在Dockerfile中使用的是基于Alpine的镜像

安装build-base以满足您的要求。

apk add build-base
英文:

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

答案7

得分: 9

你好!以下是翻译好的内容:

$ go env

检查 **CGO_ENABLED**,如果它的值是 **1**,请将其改为 **0**,方法如下:

$ export CGO_ENABLED=0
英文:
$ go env

check CGO_ENABLED if its 1 change it to 0 by

$export CGO_ENABLED=0 

答案8

得分: 5

对于我的情况:
操作系统:Windows 10

命令:
choco install mingw

如果未安装,请安装choco:
链接:https://www.liquidweb.com/kb/how-to-install-chocolatey-on-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.

答案9

得分: 4

在Windows环境下,Hyperledger无法正常工作的原因有其他答案中给出的适当解释。
为了编译目的,只需使其正常工作而无需安装任何额外的内容,您可以尝试以下操作:

go build --tags nopkcs11

这对我有效。希望对您也有效。

英文:

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.

答案10

得分: 4

你可以尝试以下方法作为临时解决方案:

cgo_enabled=0 go build

安装gcc后,确保%PATH环境变量中可以找到gcc.exe,这样问题应该就会解决。

另外,运行以下命令可以确保cgo_enabled变量在终端打开期间保持不变。这样你就不需要每次构建时都加上前缀了。

export cgo_enabled=0 go build
英文:

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 

答案11

得分: 4

对于Ubuntu,对我来说有效的方法是简单地运行:

sudo apt install gcc
英文:

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

sudo apt install gcc

答案12

得分: 4

刚刚按照以下说明进行操作,问题解决了:

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

它要求通过MSYS2安装Mingw-w64。

重要的命令是 pacman -S --needed base-devel mingw-w64-x86_64-toolchain,然后将 C:\msys64\mingw64\bin 添加到 PATH

谢谢。

英文:

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

答案13

得分: 3

在Amazon Linux 2上:

1)安装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)安装gcc

sudo yum groupinstall "Development Tools"

我建议使用软件包组进行安装,尽管可以不使用它,因为groupinstall会为您提供在Amazon Linux和Redhat、CentOS上编译软件所需的必要软件包。

英文:

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.

答案14

得分: 2

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

  1. 在http://www.mingw.org/ 上下载MinGW。
  2. 安装基本包Gcc-g++(参见此图像)。
  3. 添加Windows环境变量的路径。
  4. 重新启动并继续执行"go get ..."。
英文:

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

答案15

得分: 2

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

sudo apt-get update
sudo apt-get install build-essential

如果上述命令不起作用,请执行以下操作:

sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) main universe"

主要组件包含的是免费软件应用程序,可以自由分发,并且得到Ubuntu团队的全面支持。宇宙组件是自由、开源和Linux世界的一个快照。

然后在终端中使用以下命令安装软件包:

sudo apt-get update
sudo apt-get install build-essential

更多信息请点击这里:https://itectec.com/ubuntu/ubuntu-problem-installing-build-essential-on-14-04-1-lts-duplicate/

英文:

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/

答案16

得分: 2

只需将以下内容添加到您的 Dockerfile 中:

RUN apk add alpine-sdk
英文:

Just add this to your Dockerfile

RUN apk add alpine-sdk

答案17

得分: 1

gcc在大多数情况下是不必要的,除非你在为非Windows平台进行交叉编译,或者使用cgo。然而,如果你确实需要gcc,你应该安装MinGW,它提供了Windows平台的gcc版本(Cygwin和msys也可以工作,尽管我从未亲自测试过)。

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

英文:

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.

答案18

得分: 1

修复“exec: “gcc”: 在%PATH%中找不到可执行文件”错误的MSYS2指令:

  • 下载MSYS2。
  • 将MSYS2文件夹添加到你的$PATH环境变量中。
  • 启动MSYS2命令行程序。
  • 运行以下指令:pacman -S gcc
英文:

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.

答案19

得分: 1

请安装MINGW,安装完成后GUI将会自动启动。

你可以在以下链接中获取MINGW的安装指南:

http://mingw.org/wiki/Getting_Started

英文:

Kindly install the MINGW after GUI will automatically take.

http://mingw.org/wiki/Getting_Started

答案20

得分: 1

在Windows上,你可以通过Scoop安装gcc:

scoop install gcc
英文:

On Windows, you can install gcc by Scoop:

scoop install gcc

答案21

得分: 0

你需要下载MingGW64。
将MingGW64文件夹放入你的$PATH路径中。
运行go build xxx.go(带有cgo库)。

英文:
  1. you need to download MingGW64
  2. put MingGW64 folder into your $PATH
  3. run go build xxx.go (with cgo library)

答案22

得分: 0

你好,主要问题是你还没有将%GO_HOME%\pkg\tool\windows_amd64注册到你的环境路径中。
%GO_HOME%是你第一次安装go时的存储库。

英文:

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.

答案23

得分: 0

与其他相同,只需安装tdm-gcc,但您可以使用其终端“MinGW”,您可以从开始菜单文件夹tdm-gcc访问它,在启动后,浏览到您的项目,并再次运行它。

英文:

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

答案24

得分: 0

我是你的中文翻译助手,以下是翻译好的内容:

我是一个Windows用户,我从下面的链接下载了tdm-gcc(基于MinGW-w64):

https://jmeubank.github.io/tdm-gcc/

安装完成后,它创建了一个名为"TDM-GCC-64"的文件夹。

我将"C:\TDM-GCC-64\bin"添加到了我的PATH环境变量中,这解决了我的问题。

英文:

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.

huangapple
  • 本文由 发表于 2017年4月24日 13:03:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/43580131.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定