简体   繁体   English

golang 无法执行二进制文件:执行格式错误

[英]golang cannot execute binary file: Exec format error

my go env我的 go 环境

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=""
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT=""
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"

I compiled and successfully executed the binary on my mac and then copied it to the ubuntu machine whose go env is show above.我在我的 Mac 上编译并成功执行了二进制文件,然后将其复制到 ubuntu 机器,其 go 环境如上所示。 When I call myprog binary, I get当我调用 myprog 二进制文件时,我得到

bash: /usr/local/go/bin/myprog: cannot execute binary file: Exec format error

Since go 1.5, cross compiler has gotten pretty easy. 从1.5开始,交叉编译器变得非常简单。 Something like 就像是

env GOOS=linux GOARCH=amd64 go build -v github.com/constabulary/gb/cmd/gb

Refer to http://dave.cheney.net/2015/08/22/cross-compilation-with-go-1-5 . 请参阅http://dave.cheney.net/2015/08/22/cross-compilation-with-go-1-5

I had the same problem. 我有同样的问题。 I installed 64-bit version of go instead of 32-bit version. 我安装了64位版本的go而不是32位版本。 After installation of 32-bit version it works fine. 安装32位版本后,它工作正常。

在 Windows 上,确保您(或您的 IDE)没有运行 PowerShell - powershell 不会采用set GOOS并且不会抛出错误,并且仍会编译二进制文件,当您将二进制文件部署到服务器时,您会发现此错误。

This happened to me when I was downloading the x86 version of golang, but the VM i provisioned was an ARM cpu.当我下载 golang 的 x86 版本时,这发生在我身上,但我配置的 VM 是 ARM cpu。

You can get ARM downloads here: https://go.dev/dl/您可以在此处下载 ARM: https://go.dev/dl/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 golang 项目推送到 heroku 时收到“无法执行二进制文件:Exec 格式错误”。 为什么会这样? - Received “cannot execute binary file: Exec format error” while pushing golang project to heroku. Why is this happening? 部署到 Heroku 错误无法执行二进制文件执行格式错误 - Deploy to Heroku Error cannot execute binary file Exec format error 使用Golang Exec执行Tmux - Execute Tmux with Golang Exec 当我尝试使用 exec 在 golang 中的 cmd 上执行以下代码时,执行命令给出错误“没有这样的文件或目录”。 有人可以帮我弄这个吗? - Exec command giving error "No such file or directory" when I try to execute the below code on cmd in golang with exec. Can someone help me with this? 运行AWS Golang Lambda时出现exec格式错误 - exec format error when running AWS Golang Lambda 尝试在 golang 中执行 python 可执行文件时执行格式错误 - exec format error when trying to excute a python excutable in golang Golang:以二进制模式执行gobench - Golang: Execute the gobench on binary mode 错误:fork/exec:没有这样的文件或目录——在 docker 中运行 Golang 代码时 - Error:fork/exec : no such file or directory -- when run Golang code in docker golang对正在运行的二进制文件/进程执行命令 - golang exec a command on a running binary / process exec.command 不在 windows (golang) 上执行 - exec.command does not execute on windows (golang)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM