英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论