douyue8685 2015-02-19 13:57
浏览 57
已采纳

6g:在Go中编译外部api代码时找不到命令错误

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条回答 默认 最新

  • duanjiwu0324 2015-02-19 14:01
    关注

    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:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制