简体   繁体   English

golang 编译器错误:无法加载包:包主:在 /home/ubuntu/workspace/Go 中没有可构建的 Go 源文件

[英]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).它是为我的本机平台(我正在编码的机器)而构建的,但当我尝试定位另一个平台时则不是(使用GOOSGOARCH就像你在做的那样)。

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.

相关问题 无法加载包:包。:没有可构建的 Go 源文件 - can't load package: package .: no buildable Go source files 进行构建时“没有可构建的Go源文件”错误 - Go build “with no buildable Go source files in” error 去得到错误-无法加载包 - go get error - can't load package 文件夹中没有可构建的Go源文件 - No buildable Go source files in folder 奇怪的编译错误说“没有可构建的Go源文件” - strange compiling error saying 'no buildable Go source files' 链码示例中没有可构建的Go源文件错误 - no buildable Go source files error in Chain Code Examples Gogs 构建失败并显示“没有可构建的 Go 源文件” - Gogs build fails with "no buildable Go source files" 无法加载 package:package golang.org/dl/go1.10.7@latest:尝试安装另一个 Z34D1F91FB12E514B8567A 时,只能使用带有“go get”的 path@version 语法 - can't load package: package golang.org/dl/go1.10.7@latest: can only use path@version syntax with 'go get' when trying to install another go version go 测试失败,显示“无法加载 package 构建约束排除所有 Go 文件” - go test fails with "can't load package build constraints exclude all Go files" 如何使用 Go 模块修复 Go 构建错误“无法加载包”? - How to fix Go build error "can't load package" with Go modules?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM