Golang – C source files not allowed when not using cgo
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.
I fixed this by unsetting
GOROOT in the environment. It was pointing to another Go installation.
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.