Go程式編譯簡介

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

Go語言安裝包內建的編譯器是gc。針對不同的硬體平台,Go分別提供了一組編譯工具包:比如,6a6c6g6l就是針對X86-64平台(5*ARM8*X86)。此外gcc還有一個支援Go語言的前端:gccgo。因此如果gc不支援你當前的平台,可以嘗試用gcc

go build命令預設會使用gc編譯器。假設目前的目錄為goEx,在這個目錄下建立hello.go

package mainimport "fmt"func main() {        fmt.Println("Hello, world!")}

在目前的目錄下執行go build命令:

[root@Fedora goEx]# lshello.go[root@Fedora goEx]# go build[root@Fedora goEx]# lsgoEx  hello.go[root@Fedora goEx]# ./goExHello, world!

可以看到產生的可執行檔名字為goEx,與目錄名相同。

因為hello.gomain package,執行go build hello.go會產生名為hello的可執行檔:

[root@Fedora goEx]# go build hello.go[root@Fedora goEx]# lshello  hello.go

也可以使用-o選項指定可執行檔名字:

[root@Fedora goEx]# go build -o a.out hello.go[root@Fedora goEx]# lsa.out  hello.go[root@Fedora goEx]# ./a.outHello, world!
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.