doumei1908 2013-06-27 02:19
浏览 48
已采纳

如何用Go语言编译程序?

I'm walking the first steps with Go language and I'm trying to install it in Debian Squeeze. I follow the step of downloading the source code and then, I did this on my terminal:

cd $GOROOT/src
./all.bash

At the end, it says this:

# Checking API compatibility.
Go version is "go1.1.1", ignoring -next /root/go/api/next.txt
~pkg net, func ListenUnixgram(string, *UnixAddr) (*UDPConn, error)
~pkg syscall (darwin-386), func Fchflags(string, int) error
~pkg syscall (darwin-386-cgo), func Fchflags(string, int) error
~pkg syscall (darwin-amd64), func Fchflags(string, int) error
~pkg syscall (darwin-amd64-cgo), func Fchflags(string, int) error
~pkg syscall (freebsd-386), func Fchflags(string, int) error
~pkg syscall (freebsd-amd64), func Fchflags(string, int) error
~pkg text/template/parse, type DotNode bool
~pkg text/template/parse, type Node interface { Copy, String, Type }

    ALL TESTS PASSED

---
Installed Go for linux/amd64 in /root/go
Installed commands in /root/go/bin

So, the book says that I need to do some tests and compile it with 6g. But I try it this way:

Compile this first Go-program with: 6g test.go This compiles to a file: test.6 which is linked with the command: 6l test.6 This produces the executable named: 6.out which executes with the command: ./6.out and produces the output: Hello, world

But nothing works, my code is:

package main
func main() {
         println(“Hello”, “world”)
}

So, I do not know what more to do... I do know now the name of my compiler, so I have no idea how to compile this in Debian... If you please, give a hand with this... I would be really thankfully to you!

  • 写回答

3条回答 默认 最新

  • douxun4173 2013-06-27 06:28
    关注

    It looks like you are following instructions from:

    The Way to Go: A Thorough Introduction to the Go Programming Language By Ivo Balbaert. Section 2.3 Installing Go on a Linux system

    These instructions are out of date. They use an obsolete release of Go, release 0.60. You have installed Go release 1.1.1.

    For up-to-date instructions see Installing Go from source

    Also, when you copy programs from the book, the book uses “ (left double quotation mark) and ” (right double quotation mark) in the code examples. Go expects " (quotation mark).

    Write the test.go Go program as:

    package main
    
    func main() {
        println("Hello", "world")
    }
    

    When you installed Go, it told you it "Installed commands in /root/go/bin." You need to have /root/go/bin in your $PATH so that it can find (recognize) the Go commands.

    From the directory which contains the test.go file, run

    $ export PATH=$PATH:/root/go/bin
    $ go version
    go version go1.1.1 linux/amd64
    $ go run test.go
    Hello world
    

    If this fails, what output do you get?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?