go语言中一种常见的错误

Lepaskan: 2020-06-17 17:34:29
ke hadapan
4463 orang telah melayarinya

go语言中一种常见的错误

本文是基于mac,安装go1.14版本之后,执行一个基本的go文件报错了。

错误现象:

执行下面的go的文件报下面的错误了

# hello.go
package main

import "fmt"

func main(){
    fmt.Println("hello world")
}
Salin selepas log masuk

运行效果如下:

➜  test go run hello.go
# runtime/internal/atomic
/usr/local/go/src/runtime/internal/atomic/atomic_amd64x.go:13:6: Load redeclared in this block
    previous declaration at /usr/local/go/src/runtime/internal/atomic/atomic_amd64.go:16:24
/usr/local/go/src/runtime/internal/atomic/atomic_amd64x.go:19:6: Loadp redeclared in this block
    previous declaration at /usr/local/go/src/runtime/internal/atomic/atomic_amd64.go:22:32
/usr/local/go/src/runtime/internal/atomic/atomic_amd64x.go:25:6: Load64 redeclared in this block
    previous declaration at /usr/local/go/src/runtime/internal/atomic/atomic_amd64.go:28:26
/usr/local/go/src/runtime/internal/atomic/atomic_amd64x.go:31:6: LoadAcq redeclared in this block
    previous declaration at /usr/local/go/src/runtime/internal/atomic/atomic_amd64.go:34:27
/usr/local/go/src/runtime/internal/atomic/atomic_amd64x.go:36:6: Xadd redeclared in this block
    previous declaration at /usr/local/go/src/runtime/internal/atomic/atomic_amd64.go:39:37
/usr/local/go/src/runtime/internal/atomic/atomic_amd64x.go:39:6: Xadd64 redeclared in this block
    previous declaration at /usr/local/go/src/runtime/internal/atomic/atomic_amd64.go:42:39
/usr/local/go/src/runtime/internal/atomic/atomic_amd64x.go:42:6: Xadduintptr redeclared in this block
    previous declaration at /usr/local/go/src/runtime/internal/atomic/atomic_amd64.go:45:47
/usr/local/go/src/runtime/internal/atomic/atomic_amd64x.go:45:6: Xchg redeclared in this block
    previous declaration at /usr/local/go/src/runtime/internal/atomic/atomic_amd64.go:48:36
/usr/local/go/src/runtime/internal/atomic/atomic_amd64x.go:48:6: Xchg64 redeclared in this block
    previous declaration at /usr/local/go/src/runtime/internal/atomic/atomic_amd64.go:51:38
/usr/local/go/src/runtime/internal/atomic/atomic_amd64x.go:51:6: Xchguintptr redeclared in this block
    previous declaration at /usr/local/go/src/runtime/internal/atomic/atomic_amd64.go:54:45
/usr/local/go/src/runtime/internal/atomic/atomic_amd64x.go:51:6: too many errors
Salin selepas log masuk

原因:

由于安装新版本的时候,没有删除旧版本,导致安装包的有些关联发生错误

解决方案:

先手动删除之前安装的包,再重新按照

rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go1.14.1.darwin-amd64.tar.gz
Salin selepas log masuk

更多相关知识请关注go语言教程栏目

Atas ialah kandungan terperinci go语言中一种常见的错误. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Label berkaitan:
sumber:segmentfault.com
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!