我是golang的新手,正在尝试使用this tutorial.编写程序

但是我在编译它时抛出此错误。

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程序并运行它,它将起作用。例如,从here到第1节到第5节的所有程序,直到“Go Templates-Part 3-Template Sets”都可以正常工作。只有这个特定的教程让我感到困扰。
  • 我刚刚链接到的其他程序都没有要求我运行“6g”命令。但是它们仍然在我的机器上运行。
  • 关于出现错误的行,我正在使用正确的行来反射(reflect)计算机中的文件夹名称。

  • 他们要求运行什么:
    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
    │   │
    

    因此,我知道那里存在一些问题,但是我也知道,这可能不是导致我所看到的错误的原因,否则我会看到诸如“找不到文件”之类的错误。我只是想提及它作为其他数据。

    因此,我对此表示感谢。请让我知道是否也应该提供其他数据。

    最佳答案

    这是一个内部命令,您可以使用go tool 6g运行它。

    话虽如此,该指南已经过时,不再适用。



    替换为仅运行go build urlshortner.go甚至go run urlshortner.go
    很少要检查的资源:

  • A Tour of Go
  • Go By Example
  • Effective Go
  • 关于go - 6克: command not found error while compiling external API code in Go,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28608216/

    10-11 22:38
    查看更多