英文:
exec format error
问题
我最近在我的电脑上安装了 lubuntu 11.04。按照这个指南上的说明,从源代码安装 go,在我的电脑上安装 golang 进展顺利。为了测试我的安装,我运行了 hello.go,然后出现了这个错误:
fork/exec /tmp/go-build748212890/command-line-arguments/_obj/a.out: exec format error
我在谷歌上查找了一下,找到了一个相关的结果,说要删除该软件包,然后重新安装。但这并没有帮助。
你能告诉我是什么原因导致了这个错误,以及我该如何解决吗?
谢谢,祝你有愉快的一天!
英文:
I recently installed lubuntu 11.04 on my pc. Following this guide on installing go from source, installing golang on my pc went well. To test my installation, I ran hello.go and got this error:
fork/exec /tmp/go-build748212890/command-line-arguments/_obj/a.out: exec format error
I looked it up on google, and one of the more relevant results that I found said to remove the package, then reinstall again. That did not help.
Can you tell me what is causing this error, and how I can fix this?
Thanks, and have a nice day!
答案1
得分: 19
我遇到了这个问题 - 它非常简单:我将$GOOS设置为与我正在测试的操作系统不同的值。你不能进行跨平台测试。所以对于"go test",不要设置$GOOS。我相信你得到的"Exec format error"是由于go test试图在错误的架构/操作系统上执行某些操作引起的。
英文:
I had this problem - it was very simple: I had set $GOOS to something other than the OS I was testing on. You can't do cross-platform testing. So for "go test", don't set $GOOS. I'm pretty sure the "Exec format error" you got was a result of go test trying to execute something on the wrong architecture/OS.
答案2
得分: 0
在Windows上使用Goland时遇到了这个错误。问题是测试用例嵌套并且名称相当长,这意味着生成的二进制文件路径名称非常长。Windows的最大文件路径限制为260个字符,而二进制文件路径的总长度超过了该限制,因此出现了错误。
例如:
t.Run("Authentication Tests", func(t *testing.T) {
t.Run("Given my conditions, when the function xyz is called, we expect this super
important result", func(t *testing.T) {
})
})
解决方法是在测试用例名称中使用较少的单词。
英文:
got this error on windows from Goland. The issue was that the test cases were nested and had pretty lengthy names which meant that the resultant binary had a file path with a super long name. Windows has a max file path limit of 260 characters and the total length of the file path to the binary exceeded that limit hence the error.
e.g
t.Run("Authentication Tests", func(t *testing.T) {
t.Run("Given my conditions, when the function xyz is called, we expect this super
important result", func(t *testing.T) {
})
})
The solution was to use fewer words in the test case names
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论