1

我是 golang 的新手,我正在尝试使用本教程编写一个程序。

但是我在编译它时抛出了这个错误。

6g: command not found

这是我尝试过的:

$ go version
go version go1.4.1 darwin/amd64
  • 我已经正确设置了环境变量

这是我的 .bashrc 的样子:

 $ tail ~/.bashrc

export GOBIN=/Users/abhijeet/code/golang/go/bin  
export GOROOT=/Users/abhijeet/code/golang/go  
export GOPATH=/Users/abhijeet/code/golang/gopath  
export GOOS="darwin"  
export GOARCH="amd64"  
export PATH="$GOBIN:$PATH"
  • 我在 /etc/profile 下添加了以下行以获取它

这是它的外观:

[ -r $HOME/.bashrc ] && source $HOME/.bashrc
  • 如果我退出终端,再次启动它并回显任何变量,它们就会起作用。

  • 我已经安装了 gcc。

这是我运行“gcc --version”命令时得到的结果:

$ gcc --version

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.1.0
Thread model: posix
  • 如果我编写任何其他 go 程序并运行它,它就可以工作。例如,从这里第 1 部分到第 5 部分的所有程序,直到“Go Templates - Part 3 - Template Sets”,即使现在也可以正常工作。只有这个特定的教程让我感到困扰。

  • 我刚刚提供链接的其他程序都不需要我运行“6g”命令。但它们仍然在我的机器上运行。

  • 关于出现错误的那一行,我使用正确的那一行来反映我机器中的文件夹名称。

他们要求运行的内容:

6g -I $GOPATH/pkg/linux_amd64 urlshortener.go

我正在运行的内容:

6g -I $GOPATH/pkg/darwin_amd64 urlshortener.go
  • 重要提示:我已按照教程中的所有步骤使用外部 API。但是,如果我查看 darwin_amd64 文件夹,我根本看不到任何 urlshortener.go 文件!

我能找到的只有

darwin_amd64
├───code.google.com
│   ├───p
│   │   └───google-api-go-client
│   │       └───googleapi
│   │       │    └─── <more folders and files here>
│   │       └───urlshortener 
│   │       │   └───v1.a
│   │       └───googleapi.a
│   │ 

所以我知道那里有一些问题,但我也知道这可能不是导致我看到的错误的原因,否则我会看到像“找不到文件”这样的错误。我只是想将其作为附加数据提及。

所以我很感激这方面的任何帮助。如果我还应该提供任何其他数据,请告诉我。

4

1 回答 1

2

这是一个内部命令,您可以使用go tool 6g.

话虽如此,该指南已经过时并且不再相关。

  • 编译我使用: 6g -I $GOPATH/pkg/linux_amd64 url​​shortener.go
  • 要链接我使用: 6l -L $GOPATH/pkg/linux_amd64 url​​shortener.6

被简单地运行go build urlshortner.go甚至替换go run urlshortner.go

要检查的资源很少:

于 2015-02-19T14:01:44.180 回答