Go 1.5+:错误 – 在不使用cgo或SWIG时,不允许导入C源文件。

huangapple go评论89阅读模式
英文:

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

问题

我的程序在使用go 1.4.2版本时完美构建。安装了go 1.5版本后,我遇到了以下错误。

> 导入runtime:在不使用cgo或SWIG时不允许使用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

这个错误与程序无关。即使是一个简单的“Hello world”程序也会出现相同的错误。

英文:

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

得分: 55

> 删除旧的1.4.x Go安装,然后安装Go 1.5。

我在安装Go 1.5后遇到了同样的问题。问题在于我将Go 1.5安装在了1.4.2的相同位置。Go 1.5不再使用C语言,如果旧的C语言安装文件仍然存在,就会出现你所看到的错误。

如果你希望保留旧的安装版本,那么请将1.5安装到其他位置,并将GOROOT设置为该位置。

希望对你有所帮助。

编辑1:针对Linux用户:

如果你下载了go1.5*.tar.gz文件,那么你可能执行了以下操作:

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

你的旧文件夹中的C语言文件并没有被删除,所以正确的步骤应该是:

首先:你应该删除旧的go文件夹。

> sudo rm -rf /usr/local/go/

其次:然后运行以下命令

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

英文:

> 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

得分: 5

如果你使用brew来升级你的Go到1.5版本,以下是我让它正常工作的步骤:

  1. 在%GOPATH%中删除pkg文件夹。
  2. 重新加载终端(控制台)会话,确保Go env指向Go 1.5文件夹。

顺便说一下:如果你想通过brew switch go 1.4.2从Go 1.5切换回Go 1.4.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

得分: 2

我遇到了同样的问题,因为我在我的机器上安装了两个版本的golang,一个是从官方网站下载的,另一个是通过Homebrew安装的。

而GOROOT与go二进制文件不匹配,我只需要将GOROOT替换为正确的路径,问题就解决了。

export GOROOT=/usr/local/opt/go/libexec # 通过brew安装

英文:

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

得分: 0

我在我的编辑器(sublime text 2)中遇到了这个问题。我在保存时调用了go build命令,但是我的编辑器似乎指向的是go 1.4.x而不是新安装的1.5版本。

  • 我通过简单地退出并重新打开我的编辑器来解决了这个问题。
英文:

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.

huangapple
  • 本文由 发表于 2015年8月20日 18:01:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/32115229.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定