简体   繁体   English

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

[英]Golang - C source files not allowed when not using cgo

When trying to run go build in my src directory, I get this error: 当我尝试在我的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 导入运行时:不使用cgo时不允许使用C源文件: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. 当我第一次开始学习Go时,我在安装了1.2版本的Ubuntu笔记本电脑(14.04 LTS,64bit)上运行了sudo apt-get install golang 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. 然后我运行autoremove去掉它,然后从golang网站安装了1,4。

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. 谷歌搜索错误表明它与以前安装的go版本有关,但我认为autoremove将清理它和任何依赖关系(它似乎,因为我确保我无法在任何地方找到golang,然后从安装资源。

Any clues? 有线索吗?

I fixed this by unsetting GOROOT in the environment. 我通过在环境中GOROOT来解决这个问题。 It was pointing to another Go installation. 它指向另一个Go安装。

So James was on the right track. 所以詹姆斯走在了正确的轨道上。 I had gcc installed, but not the 32 bit version. 我安装了gcc,但不是32位版本。 Following advice from https://github.com/golang/go/wiki/InstallFromSource#Install_C_tools on how to install the 32 bit version fixed the issue. 遵循https://github.com/golang/go/wiki/InstallFromSource#Install_C_tools关于如何安装32位版本的建议修复了该问题。

I had a similar problem after upgrading to go 1.5. 升级到1.5后我遇到了类似的问题。 Removing the /usr/local/go directory and reinstalling from the tarball fixed the problem. 删除/usr/local/go目录并从tarball重新安装修复了问题。

if you install Go 1.4 and then install Go 1.5. 如果您安装Go 1.4然后安装Go 1.5。 But don't change GOROOT environment variables. 但是不要改变GOROOT环境变量。 Change GOROOT point to GO 1.5 path. 将GOROOT点改为GO 1.5路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM