Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Golang - C source files not allowed when not using cgo

Tags:

linux

go

ubuntu

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.

Any clues?

like image 876
Grayda Avatar asked Mar 17 '23 11:03

Grayda


2 Answers

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

like image 128
Matt Joiner Avatar answered Mar 20 '23 01:03

Matt Joiner


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.

like image 32
Grayda Avatar answered Mar 19 '23 23:03

Grayda