简体   繁体   中英

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.

Any clues?

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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