将 Go 语言与 MSYS2 一起使用
Posted
技术标签:
【中文标题】将 Go 语言与 MSYS2 一起使用【英文标题】:Use Go lang with MSYS2 【发布时间】:2016-09-08 23:08:10 【问题描述】:我想使用 Go,这是一种在 Windows 上使用 MSYS2 的编程语言。 我应该使用哪个包以及如何避免以下错误:
package bufio: unrecognized import path "bufio"
package bytes: unrecognized import path "bytes"
package crypto: unrecognized import path "crypto"
package crypto/des: unrecognized import path "crypto/des"
package crypto/hmac: unrecognized import path "crypto/hmac"
package crypto/md5: unrecognized import path "crypto/md5"
package crypto/rand: unrecognized import path "crypto/rand"
package crypto/rc4: unrecognized import path "crypto/rc4"
package crypto/sha256: unrecognized import path "crypto/sha256"
package crypto/tls: unrecognized import path "crypto/tls"
package crypto/x509: unrecognized import path "crypto/x509"
package encoding/base64: unrecognized import path "encoding/base64"
package encoding/binary: unrecognized import path "encoding/binary"
package encoding/hex: unrecognized import path "encoding/hex"
package encoding/json: unrecognized import path "encoding/json"
package encoding/xml: unrecognized import path "encoding/xml"
package errors: unrecognized import path "errors"
package fmt: unrecognized import path "fmt"
package io: unrecognized import path "io"
package os: unrecognized import path "os"
package path/filepath: unrecognized import path "path/filepath"
package runtime: unrecognized import path "runtime"
package strconv: unrecognized import path "strconv"
package strings: unrecognized import path "strings"
package sync: unrecognized import path "sync"
package time: unrecognized import path "time"
package os/exec: unrecognized import path "os/exec"
package syscall: unrecognized import path "syscall"
package io/ioutil: unrecognized import path "io/ioutil"
package regexp: unrecognized import path "regexp"
package hash: unrecognized import path "hash"
package net: unrecognized import path "net"
package sync/atomic: unrecognized import path "sync/atomic"
package unsafe: unrecognized import path "unsafe"
package hash/crc32: unrecognized import path "hash/crc32"
package reflect: unrecognized import path "reflect"
package unicode/utf16: unrecognized import path "unicode/utf16"
package unicode: unrecognized import path "unicode"
package unicode/utf8: unrecognized import path "unicode/utf8"
package math: unrecognized import path "math"
package net/http: unrecognized import path "net/http"
package net/http/httputil: unrecognized import path "net/http/httputil"
package net/url: unrecognized import path "net/url"
package path: unrecognized import path "path"
package sort: unrecognized import path "sort"
package text/template: unrecognized import path "text/template"
package log: unrecognized import path "log"
package os/signal: unrecognized import path "os/signal"
【问题讨论】:
【参考方案1】:安装 Go 语言:pacman -S mingw-w64-x86_64-go
配置环境变量:
export GOROOT=/mingw64/lib/go
export GOPATH=/mingw64
开始使用 Go :)
go get
将下载(在mingw64/src
中)、编译并使二进制文件在您的路径上可用(/mingw64/bin
)
【讨论】:
这些天,很久以前不应该明确设置GOROOT
。
是的,不幸的是,在 MSYS2 上,GOROOT 的默认值不正确,甚至go env
在这种情况下也无法运行:(
不幸的是,在做了这一切之后,go 不起作用,二进制文件不存在
安装mingw-w64-x86_64-go
后,GOROOT
被设置为我的正确路径。
pacman -S mingw-w64-x86_64-go
之后,旧环境仍在您的终端中运行。关闭该会话,开始一个新会话,然后运行go version
。刚刚为我工作。以上是关于将 Go 语言与 MSYS2 一起使用的主要内容,如果未能解决你的问题,请参考以下文章