Go 1.5+ : Error - imports runtime: C source files not allowed when not using cgo or SWIG

若如初见. 提交于 2020-12-29 02:47:06

问题


My program was building perfectly with go 1.4.2. After installing go 1.5, I am getting following error.

imports runtime: C source files not allowed when not using cgo or SWIG: 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

The error is not program dependent. Even a "Hello world" programs is throwing the same error.


回答1:


Remove Old 1.4.x go installation and then install go 1.5.

I faced the same problem after installing go 1.5. The issue is that I installed go 1.5 at the same place of 1.4.2. Go 1.5 does not use C anymore and if old C installation files are present it throws the error as you are shown.

if you want the old installation to be present as well then install 1.5 to some other location and set GOROOT to that location.

Hope it helps.

Edit 1: For Linux Users:

if you downloaded go1.5*.tar.gz then you did this:

tar -C /usr/local/ -xvf go1.5.linux-amd64.tar.gz

Your old folder C files are not deleted, so the correct process is:

First: You should delete you old go folder.

sudo rm -rf /usr/local/go/

Second: Then run

tar -C /usr/local/ -xvf go1.5.x.linux-amd64.tar.gz




回答2:


If you use brew to upgrade your go to Go 1.5. Here is my step to make it work:

  1. Remove pkg folder in %GOPATH%
  2. Reload terminal(console) session, make sure Go env goes to Go 1.5 folder.

BTW: You need do the same thing if you want to switch from Go 1.5 back Go 1.4.2 via brew switch go 1.4.2.




回答3:


I have the same problem because I installed two version of golang on my machine, one from offical site and the other is from homebrew.

And the GOROOT isn't match the go binary, I just replace the GOROOT with the right one, then done.

export GOROOT=/usr/local/opt/go/libexec # install via brew



回答4:


I experienced this issue within my editor (sublime text 2). I call go build upon saving, it would appear my editor was pointing to go 1.4.x rather than the newly installed 1.5.

  • I solved this by simply quitting and reopening my editor.


来源:https://stackoverflow.com/questions/32115229/go-1-5-error-imports-runtime-c-source-files-not-allowed-when-not-using-cgo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!