英文:
6g: command not found error while compiling external API code in Go
问题
我是你的中文翻译助手,以下是翻译好的内容:
我刚开始学习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
│ │ │ └─── <更多文件夹和文件>
│ │ └───urlshortener
│ │ │ └───v1.a
│ │ └───googleapi.a
│ │
所以我知道这里可能有一些问题,但我也知道这可能不是导致我看到的错误的原因,否则我应该会看到 "文件未找到" 的错误。我只是想提及它作为额外的数据。
所以我非常感谢任何关于这个问题的帮助。如果需要提供任何其他数据,请告诉我。
英文:
I'm new to golang and I'm trying to write a program using this tutorial.
However I'm getting this error thrown while compiling it.
6g: command not found
Here's what I've tried:
$ go version
go version go1.4.1 darwin/amd64
- I've set environment variables properly
Here's how my .bashrc looks like:
$ 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"
- I've added below line under /etc/profile to source it
Here's how it looks:
[ -r $HOME/.bashrc ] && source $HOME/.bashrc
-
If I quit the terminal, launch it again and echo any of the variables, they work.
-
I have gcc installed.
Here's what I get when I run "gcc --version" command:
$ 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
-
If I write any other go program and run it, it works. For instance, all the programs from section 1 through 5 from here, and till the "Go Templates - Part 3 - Template Sets" work just fine even now. Only this particular tutorial is troubling me.
-
None of the other programs I just gave link to, required me to run the "6g" command. But they still run on my machine.
-
About the line where I get error, I am using the right one to reflect folder names in my machine.
What they've asked to run:
6g -I $GOPATH/pkg/linux_amd64 urlshortener.go
What I'm running:
6g -I $GOPATH/pkg/darwin_amd64 urlshortener.go
- Important: I have followed all the steps in the tutorial for using external apis. However, if I look inside the darwin_amd64 folder, I don't see any urlshortener.go file at all!
All I can find is
darwin_amd64
├───code.google.com
│ ├───p
│ │ └───google-api-go-client
│ │ └───googleapi
│ │ │ └─── <more folders and files here>
│ │ └───urlshortener
│ │ │ └───v1.a
│ │ └───googleapi.a
│ │
So I know there's some problem there, but I also know that this probably isn't what is causing the error I'm seeing, otherwise I would have seen the error like "file not found". I just wanted to mention it as an additional data.
So I appreciate any help on this. Please let me know if I should provide any additional data as well.
答案1
得分: 2
这是一个内部命令,你可以使用go tool 6g
来运行它。
话虽如此,那个指南已经非常过时,不再相关。
> * 编译时我使用了:6g -I $GOPATH/pkg/linux_amd64 urlshortener.go
> * 链接时我使用了:6l -L $GOPATH/pkg/linux_amd64 urlshortener.6
可以简单地用go build urlshortner.go
或者go run urlshortner.go
来替代。
以下是一些可以参考的资源:
英文:
It's an internal command, you can run it with go tool 6g
.
That being said, that guide is extremely outdated and not relevant anymore.
> * To compile I used: 6g -I $GOPATH/pkg/linux_amd64 urlshortener.go
> * To link I used: 6l -L $GOPATH/pkg/linux_amd64 urlshortener.6
Is replaced with simply running go build urlshortner.go
or even go run urlshortner.go
Few resources to check:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论