Golang – 不使用 cgo 时不允许使用 C 源文件。

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

Golang - C source files not allowed when not using cgo

问题

在我的src目录中尝试运行go build时,我遇到了这个错误:

> imports runtime: C source files not allowed when not using cgo: atomic_amd64x.c defs.c float.c heapdump.c lfstack.c malloc.c mcache.c mcentral.c mem_linux.c mfixalloc.c mgc0.c mheap.c msize.c os_linux.c panic.c parfor.c proc.c runtime.c signal.c signal_amd64x.c signal_unix.c stack.c string.c sys_x86.c vdso_linux_amd64.c

当我开始学习Go时,在我的Ubuntu笔记本电脑(14.04 LTS,64位)上运行了sudo apt-get install golang,安装了版本1.2。那个运行得很好,我能够构建、安装和运行应用程序。然后我运行了autoremove来卸载它,然后从golang网站上安装了1.4。

这里发生了什么,我该如何修复它?通过谷歌搜索这个错误显示它与先前安装的go版本有关,但我以为autoremove会清理它和任何依赖项(似乎是这样,因为我确保在安装之前找不到任何golang)。有什么线索吗?

英文:

When trying to run go build in my src directory, I get this error:

> imports runtime: C source files not allowed when not using cgo: atomic_amd64x.c defs.c float.c heapdump.c lfstack.c malloc.c mcache.c mcentral.c mem_linux.c mfixalloc.c mgc0.c mheap.c msize.c os_linux.c panic.c parfor.c proc.c runtime.c signal.c signal_amd64x.c signal_unix.c stack.c string.c sys_x86.c vdso_linux_amd64.c

When I first started learning Go I ran sudo apt-get install golang on my Ubuntu laptop (14.04 LTS, 64bit) which installed version 1.2. That ran fine and I was able to build, install and run apps. I then ran autoremove to get rid of it, then installed 1,4 from the golang website.

What's going on here, and how can I fix it? Googling the error shows that it has something to do with a previously installed version of go, but I thought autoremove would clean it and any dependencies up (which it seemed to, as I made sure I couldn't find golang anywhere, before installing from source.

Any clues?

答案1

得分: 4

我通过在环境中取消设置GOROOT来解决了这个问题。它指向另一个Go安装位置。

英文:

I fixed this by unsetting GOROOT in the environment. It was pointing to another Go installation.

答案2

得分: 2

所以詹姆斯是对的。我已经安装了gcc,但没有32位版本。根据https://github.com/golang/go/wiki/InstallFromSource#Install_C_tools上的建议安装32位版本解决了这个问题。

英文:

So James was on the right track. I had gcc installed, but not the 32 bit version. Following advice from https://github.com/golang/go/wiki/InstallFromSource#Install_C_tools on how to install the 32 bit version fixed the issue.

答案3

得分: 1

我在升级到Go 1.5后遇到了类似的问题。删除/usr/local/go目录并从tarball重新安装解决了这个问题。

英文:

I had a similar problem after upgrading to go 1.5. Removing the /usr/local/go directory and reinstalling from the tarball fixed the problem.

答案4

得分: 0

如果你安装了Go 1.4,然后再安装Go 1.5,但没有更改GOROOT环境变量。请将GOROOT指向Go 1.5的路径。

英文:

if you install Go 1.4 and then install Go 1.5. But don't change GOROOT environment variables.
Change GOROOT point to GO 1.5 path.

huangapple
  • 本文由 发表于 2015年1月5日 10:57:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/27772831.html
匿名

发表评论

匿名网友

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

确定