GO: {GOOS}和{GOARCH}在环境中未被识别。

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

GO: {GOOS} and {GOARCH} not recognised in environment

问题

我想将我的目录更改为go/pkg/darwin_amd64,但是$ cd $GOPATH/pkg/${GOOS}_${GOARCH}无法找到该文件夹,尽管目录存在。

$ echo $GOPATH/pkg/${GOOS}_${GOARCH}输出的是/go/pkg/_而不是/go/pkg/darwin_amd64

$ go env命令输出的内容如下:

GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/sahilkapoor/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"

我们可以看到这里定义了GOOSGOARCH。我正在使用Mac OSX 10.10.3上的终端。我漏掉了什么?

英文:

I want to change my diretory to go/pkg/darwin_amd64 but $ cd $GOPATH/pkg/${GOOS}_${GOARCH} doesn't find the folder though directory exists.

$ echo $GOPATH/pkg/${GOOS}_${GOARCH} gives /go/pkg/_ instead of /go/pkg/darwin_amd64.

$ go env prints:

GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/sahilkapoor/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"

We can see that GOOS and GOARCH are defined here. I am using terminal on Mac OSX 10.10.3. What am I missing?

答案1

得分: 4

$GOOS$GOARCH只有在你导出它们到你的shell环境中时才会被定义(除非你正在进行交叉编译,否则这种情况不太可能发生)。

当你运行go env时,如果这些变量没有被你的环境覆盖,将显示默认值。你应该将你的命令修改为以下形式以获得所需的结果:

cd $(go env GOPATH)/pkg/$(go env GOOS)_$(go env GOARCH)
英文:

$GOOS and $GOARCH will only be defined in your shell if you have exported them (which, unless you are doing cross compilation, is unlikely).

When you run go env, default values are shown when they have not been overwritten by your environment. You should change your command to the following to get the desired results:

cd $(go env GOPATH)/pkg/$(go env GOOS)_$(go env GOARCH)

huangapple
  • 本文由 发表于 2015年6月29日 22:51:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/31118836.html
匿名

发表评论

匿名网友

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

确定