gpt4 book ai didi

go - 6g : command not found error while compiling external API code in Go

转载 作者:IT王子 更新时间:2023-10-29 02:05:30 25 4
gpt4 key购买 nike

我是 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 程序并运行它,它就可以工作。例如,第 1 节到第 5 节的所有程序来自 here ,直到“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 运行它。

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

  • To compile I used: 6g -I $GOPATH/pkg/linux_amd64 urlshortener.go
  • To link I used: 6l -L $GOPATH/pkg/linux_amd64 urlshortener.6

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

要检查的资源很少:

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com