golang compiler error: can't load package: package main: no buildable Go source files in /home/ubuntu/workspace/Go

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

golang compiler error: can't load package: package main: no buildable Go source files in /home/ubuntu/workspace/Go

问题

我正在尝试编译一个Go程序。代码是一个小的x11窗口管理器,可以在这里找到(代码有98行,太长了无法在这里发布)。

这是我在x86-64 Ubuntu上运行的命令:

GOOS=linux GOARCH=386 go build littlewm.go

这个命令在同一目录中的其他文件上运行得很好。然而,当我尝试编译这个文件时,我得到以下错误:

can't load package: package main: no buildable Go source files in /home/ubuntu/workspace/Go

这与gopath变量无关,因为我已经成功地编译了同一目录中的其他程序。我怀疑这可能与代码本身或我缺少的某些选项有关。因此,这不是一个已有问题的重复,很可能是独特的,因为我没有从其他类似的问题中得到我想要的答案。非常感谢任何帮助。

谢谢!

英文:

I am attempting to compile a go program. The code is a small x11 window manager, found HERE. (The code is 98 lines, too long to post here)

Here is the command I run, on x86-64 Ubuntu:

GOOS=linux GOARCH=386 go build littlewm.go

This command works fine on other files in the same directory. However, when I try to compile this one, I get the following error:

can't load package: package main: no buildable Go source files in /home/ubuntu/workspace/Go

This does not involve the gopath variable, as I have successfully compiled other programs in the same directory. I have a suspicion it involves the code itself or some option I am lacking. As such, this is not really a duplicate of an existing question and is quite possibly unique, since I am not getting the answer I want from other similar questions. Any help is appreciated greatly.

Thanks!

答案1

得分: 1

我在尝试构建自己的Go程序时遇到了类似的问题。我刚刚添加了GCO来与一些本地C代码库进行交互。它在本地平台上(我编码的机器)上构建成功,但在尝试针对另一个平台进行构建时(使用GOOSGOARCH,就像你正在做的那样),却无法构建成功。

将CGO_ENABLED设置为1(如david的评论中提到的)解决了我的问题:

CGO_ENABLED=1 GOOS=linux GOARCH=386 go build littlewm.go

我正在使用一个Makefile来为多个平台构建多个规则,所以我在Makefile的顶部附近加入了以下内容:

export CGO_ENABLED = 1

这样我就不需要为每个平台单独指定它了。

英文:

I encountered a similar problem when trying to build my own go program.
I had just added GCO to interface with some native C code in a library.
It built for me for the native platform (the machine I was coding on), but not when I tried to target another platform (using GOOS and GOARCH as you're doing).

Setting CGO_ENABLED to 1 (as mentioned in david's comment) fixed the problem for me:

CGO_ENABLED=1 GOOS=linux GOARCH=386 go build littlewm.go

I was using a makefile to build for multiple platforms using multiple rules, so for me, I put

export CGO_ENABLED = 1

near the top of my makefile so that I didn't need to specify it for each platform.

huangapple
  • 本文由 发表于 2017年2月19日 05:37:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/42320962.html
匿名

发表评论

匿名网友

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

确定