[英]exec: "gcc": executable file not found in %PATH% when trying go build
I am using Windows 10. When I tried to build Chaincode it 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"
)
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++ 编译器和库。
gcc (the GNU Compiler Collection) provides a C compiler. gcc (GNU Compiler Collection)提供了一个 C 编译器。 On Windows, install TDM-GCC .
在 Windows 上,安装TDM-GCC 。 The
github.com/miekg/pkcs11
package uses cgo . github.com/miekg/pkcs11
包使用cgo 。 Cgo enables the creation of Go packages that call C code. Cgo 允许创建调用 C 代码的 Go 包。
1) Install .exe
from > https://sourceforge.net/projects/mingw-w64/ 1) 从 > https://sourceforge.net/projects/mingw-w64/安装
.exe
1.2) ! 1.2)! use
x86_64
architecture使用
x86_64
架构
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
. 2) 将
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin
添加到User Variables
和System Variables
的PATH
中。 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.要编辑
Path
变量,请按Windows
键,键入“路径”,选择“编辑系统环境变量”,单击“环境变量”,在System variables
和User variables
中找到Path
变量,然后进行编辑。
在 Windows 上安装http://tdm-gcc.tdragon.net/download ,仅此而已。
If you are using an alpine based image with your Dockerfile如果您在 Dockerfile 中使用基于 alpine 的映像
Install build-base
which will be met with your requirements.安装将满足您的要求
build-base
。
apk add build-base
The proper explanations why go build does not work for hyperledger in Windows environment are given as other answers.其他答案给出了为什么 go build 不适用于 Windows 环境中的 hyperledger 的正确解释。 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.
我希望同样适用于你。
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.运行这个也将确保只要终端打开,cgo_enabled 变量就会保持这种状态。 That way you don't have to prefix it each time you do a build.
这样您就不必在每次构建时都为其添加前缀。
export cgo_enabled=0 go build
For my case : os: windows 10就我而言:操作系统:Windows 10
command:命令:
choco install mingw
install choco if not installed: Link: https://www.liquidweb.com/kb/how-to-install-chocolatey-on-windows/如果未安装,请安装 choco:链接: https ://www.liquidweb.com/kb/how-to-install-chocolatey-on-windows/
worked for me.为我工作。
$ go env
检查CGO_ENABLED如果其1将其更改为0
$export CGO_ENABLED=0
on Ubuntu its very easy but on windows need to do it:在 Ubuntu 上非常简单,但在 Windows 上需要这样做:
If you are running Ubuntu do:如果您正在运行 Ubuntu,请执行以下操作:
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.主要组件包含的应用程序是免费软件,可以自由重新分发,并得到 Ubuntu 团队的完全支持。 & The universe component is a snapshot of the free, open-source, and Linux world.
& Universe 组件是自由、开源和 Linux 世界的快照。
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/有关更多信息,请单击此处: https ://itectec.com/ubuntu/ubuntu-problem-installing-build-essential-on-14-04-1-lts-duplicate/
For Ubuntu, what worked for me was to simply run:对于 Ubuntu,对我有用的是简单地运行:
sudo apt install gcc sudo apt install gcc
gcc should not be necessary, unless you are cross compiling for a non-windows platform, or use cgo. gcc 应该不是必需的,除非您正在为非 Windows 平台进行交叉编译,或者使用 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,则应该安装 MinGW,它为 Windows 提供了 gcc 端口(Cygwin 和 msys 也应该可以工作,尽管我从未实际测试过)。
Edit: I see from your error message now, that it is a dependency that requires gcc.编辑:我现在从您的错误消息中看到,它是一个需要 gcc 的依赖项。 If you didn't already know this, gcc is ac/c++ compiler, and in this case it is probably needed to compile c source files included by a dependency or sub-dependency.
如果您还不知道,gcc 是 ac/c++ 编译器,在这种情况下,可能需要编译依赖或子依赖包含的 c 源文件。
Instruction to fix the " exec: “gcc”: executable file not found in %PATH% " error with MSYS2:使用 MSYS2 修复“ exec: “gcc”: executable file not found in %PATH% ”错误的说明:
pacman -S gcc
.pacman -S gcc
。Kindly install the MINGW after GUI will automatically take.请安装 MINGW 后 GUI 会自动占用。
http://mingw.org/wiki/Getting_Started http://mingw.org/wiki/Getting_Started
Hi jaswanth the main problem is that you haven't register your %GO_HOME%\pkg\tool\windows_amd64 to yuour Environment Path.嗨,jaswanth,主要问题是您尚未将 %GO_HOME%\pkg\tool\windows_amd64 注册到您的环境路径。 %GO_HOME% is the repository where you install your go at the first time.
%GO_HOME% 是您第一次安装 go 的存储库。
和其他一样,只需安装 tdm-gcc,但你可以使用它的终端“MinGW”,你可以从开始菜单文件夹 tdm-gcc 访问它,启动后,浏览到你的项目,然后再次运行它
在 Windows 上,您可以通过 Scoop 安装 gcc:
scoop install gcc
I'm a Windows user and I downloaded tdm-gcc ( MinGW-w64 based ) from the link below:我是 Windows 用户,我从以下链接下载了 tdm-gcc(基于 MinGW-w64 ):
https://jmeubank.github.io/tdm-gcc/ https://jmeubank.github.io/tdm-gcc/
After installation, it made a folder named "TDM-GCC-64".安装后,它创建了一个名为“TDM-GCC-64”的文件夹。
I added " C:\TDM-GCC-64\bin " to my PATH , And it fixed my problem.我将“ C:\TDM-GCC-64\bin ”添加到我的PATH中,它解决了我的问题。
只需将其添加到您的Dockerfile
RUN apk add alpine-sdk
On Amazon Linux 2:在亚马逊 Linux 2 上:
Install go安装去
wget https://go.dev/dl/go1.18.1.linux-amd64.tar.gz 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 rm -rf /usr/local/go && tar -C /usr/local -xzf go1.18.1.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin导出 PATH=$PATH:/usr/local/go/bin
Install gcc安装 gcc
sudo yum groupinstall "Development Tools" sudo yum groupinstall “开发工具”
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.我建议使用包组,即使没有它也可以完成,因为 groupinstall 为您提供了在 Amazon Linux 和 Redhat、CentOS 上编译软件所需的包。
just followed instructions from following and it solve my issue只是按照以下说明进行操作,它解决了我的问题
https://code.visualstudio.com/docs/cpp/config-mingw https://code.visualstudio.com/docs/cpp/config-mingw
it ask to install Mingw-w64 via MSYS2它要求通过MSYS2安装 Mingw-w64
important command is pacman -S --needed base-devel mingw-w64-x86_64-toolchain
then add C:\msys64\mingw64\bin
to PATH
重要的命令是
pacman -S --needed base-devel mingw-w64-x86_64-toolchain
然后将C:\msys64\mingw64\bin
添加到PATH
thanks谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.