简体   繁体   English

exec:“gcc”:尝试构建时在 %PATH% 中找不到可执行文件

[英]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"
)

It's running fine in Docker .它在Docker中运行良好。

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 VariablesSystem VariablesPATH中。 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 variablesUser variables中找到Path变量,然后进行编辑。

I also encountered this message, but in my case, it was missing gcc.exe .我也遇到了这条消息,但就我而言,它缺少gcc.exe I used choco and installed mingw , and then it worked.我使用了choco并安装了mingw ,然后它就起作用了。

details:细节:

  1. download choco下载巧克力
  2. choco install mingw -y
  3. check: gcc -v检查: gcc -v

在 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 上需要这样做:

  1. download MinGW on http://www.mingw.org/http://www.mingw.org/上下载 MinGW
  2. install on basic package Gcc-g++ (see this image )安装在基本包 Gcc-g++ 上(参见此图
  3. add on environment Patch of windows variables.添加windows变量的环境补丁。
  4. restart and continue with "go get ..."重新启动并继续“go get ...”

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% ”错误的说明:

  • Download MSYS2.下载 MSYS2。
  • Put MSYS2 folder into your $PATH.将 MSYS2 文件夹放入您的 $PATH。
  • Start the MSYS2 command line program.启动 MSYS2 命令行程序。
  • Run this command: 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

  1. you need to download MingGW64您需要下载 MingGW64
  2. put MingGW64 folder into your $PATH将 MingGW64 文件夹放入您的 $PATH
  3. run go build xxx.go (with cgo library)运行 go build xxx.go(带有 cgo 库)

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 上:

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

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

相关问题 尝试构建 docker 映像时,我收到“”gcc”:在 $PATH 中找不到可执行文件” - When trying to build docker image, I get ""gcc": executable file not found in $PATH" 在 Windows 上运行 docker 映像会导致“oci 运行时错误:exec:“bash”:在 $PATH 中找不到可执行文件。” - Run a docker image on Windows results in "oci runtime error: exec: "bash": executable file not found in $PATH." windows 上的 kubectl diff 返回错误:在 PATH 中找不到可执行文件 - kubectl diff on windows returns an error: executable file not found in PATH dbghelp何时从嵌入在可执行文件中的路径加载符号 - When does dbghelp loads symbol from path embeded in executable file Go ZeroMQ:尝试在 Windows 上构建 VS 代码时出现 Linker 问题 - Go ZeroMQ: Linker problem when trying to build in VS Code on Windows 错误在Windows上使用gcc进行构建 - Error go build using gcc on windows 路径中找不到程序“ g ++”和“ gcc” - program “g++” and “gcc” not found in path 如何更改“go build”的构建路径? - How to change build path for “go build”? 在 PATH 变量中找不到尝试运行的可执行文件“cmd.exe”Vagrant。 这是一个错误。 请验证此软件是否已安装 - The executable 'cmd.exe' Vagrant is trying to run was not found in the PATH variable. This is an error. Please verify this software is installed 使用可执行文件的完整路径并以管理员身份运行时,Windows 10无法访问指定的设备,路径或文件 - Windows 10 cannot access the specified device, path, or file when using full path to executable, running as Administrator
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM