[英]golang compiler error: can't load package: package main: no buildable Go source files in /home/ubuntu/workspace/Go
I am attempting to compile a go program.我正在尝试编译一个 go 程序。 The code is a small x11 window manager, found HERE .该代码是一个小型 x11 窗口管理器,可在此处找到。 (The code is 98 lines, too long to post here) (代码是98行,太长了就不贴了)
Here is the command I run, on x86-64 Ubuntu:这是我在 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.这不涉及gopath
变量,因为我已经成功编译了同一目录中的其他程序。 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!谢谢!
I encountered a similar problem when trying to build my own go program.我在尝试构建自己的 go 程序时遇到了类似的问题。 I had just added GCO to interface with some native C code in a library.我刚刚添加了 GCO 以与库中的一些本机 C 代码交互。 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).它是为我的本机平台(我正在编码的机器)而构建的,但当我尝试定位另一个平台时则不是(使用GOOS
和GOARCH
就像你在做的那样)。
Setting CGO_ENABLED to 1 (as mentioned in david's comment) fixed the problem for me:将 CGO_ENABLED 设置为 1(如 david 的评论中所述)为我解决了这个问题:
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我正在使用 makefile 使用多个规则为多个平台构建,所以对我来说,我把
export CGO_ENABLED = 1
near the top of my makefile so that I didn't need to specify it for each platform.靠近我的 makefile 顶部,这样我就不需要为每个平台指定它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.