go語言編譯 go語言編譯工具

Go語言編譯器TinyGo,基于LLVM,在微控制器和小系統(tǒng)上編譯和運(yùn)行

TinyGo是一個(gè)為微控制器、WebAssembly(Wasm)和命令行工具等小型場(chǎng)景設(shè)計(jì)的Go語言編譯器。TinyGo重用了Go語言工具和LLVM使用的庫(kù),以編譯用Go語言編寫的程序。目前,該項(xiàng)目在GitHub上已經(jīng)積累了10.1k的Star。

創(chuàng)新互聯(lián)建站自2013年創(chuàng)立以來,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元鐵西做網(wǎng)站,已為上家服務(wù),為鐵西各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:13518219792

如下為一個(gè)示例程序,當(dāng)運(yùn)行在任何支持的帶板載LED的主板上時(shí),則會(huì)點(diǎn)亮內(nèi)置LED。

上述程序可以在單片機(jī)、Adafruit ItsyBitsy M0微控制器或任何支持的帶內(nèi)置LED的板上進(jìn)行編譯和不需要修改的運(yùn)行,只要設(shè)置正確的TinyGo編譯器目標(biāo)即可。例如,設(shè)置如下目標(biāo)可以編譯和點(diǎn)亮 單片機(jī)。

項(xiàng)目概述

TinyGo項(xiàng)目旨在將Go語言引入到具有單進(jìn)程或核心的微控制器和小系統(tǒng)。TinyGo類似于emgo,但主要的區(qū)別在于作者想要保留Go內(nèi)存模型。另一個(gè)區(qū)別在于TinyGo在內(nèi)部使用LLVM,因而可以獲得更小更高效的代碼以及更高的靈活性。

創(chuàng)建TinyGo項(xiàng)目的初衷是,如果Python可以在微控制器上運(yùn)行,Go語言當(dāng)然也應(yīng)該能夠在更低級(jí)微設(shè)備上運(yùn)行。

支持設(shè)備

你可以為微控制器、WebAssembly和Linux編譯TinyGo程序。目前,TinyGo支持以下85種微處理器板。

更多技術(shù)細(xì)節(jié)請(qǐng)參閱原項(xiàng)目。

windows 怎么編譯 go語言

1、解壓壓縮包到go工作目錄,如解壓到E:\opensource\go\go,解壓后的目錄結(jié)構(gòu)如下:

E:\opensource\go\go

├─api

├─bin

│ ├─go.exe

│ ├─godoc.exe

│ └─gofmt.exe

├─doc

├─include

├─lib

├─misc

├─pkg

├─src

└─test

2、增加環(huán)境變量GOROOT,取值為上面的go工作目錄

3、Path環(huán)境變量中添加";%GOROOT%\bin",以便能夠直接調(diào)用go命令來編譯go代碼,至此go編譯環(huán)境就配置好了

注:如果不想手動(dòng)設(shè)置系統(tǒng)環(huán)境變量,也可下載go啟動(dòng)環(huán)境批處理附件,

修改goenv.bat文件中的GOROOT值為上面的go工作目錄后直接雙擊該bat文件,go編譯環(huán)境變量即設(shè)置完成。

4、測(cè)試go編譯環(huán)境,啟動(dòng)一個(gè)cmd窗口,直接輸入go,看到下面的提示就是搭建成功了

E:\opensource\go\gogo

Go is a tool for managing Go source code.

Usage:

go command [arguments]

The commands are:

build compile packages and dependencies

clean remove object files

doc run godoc on package sources

env print Go environment information

fix run go tool fix on packages

fmt run gofmt on package sources

get download and install packages and dependencies

install compile and install packages and dependencies

list list packages

run compile and run Go program

test test packages

tool run specified go tool

version print Go version

vet run go tool vet on packages

Use "go help [command]" for more information about a command.

Additional help topics:

gopath GOPATH environment variable

packages description of package lists

remote remote import path syntax

testflag description of testing flags

testfunc description of testing functions

Use "go help [topic]" for more information about that topic.

5、編譯helloworld測(cè)試程序,go語言包中test目錄帶有helloworld.go測(cè)試程序,源碼見"附一 helloworld.go",

直接調(diào)用"go build helloworld.go"就生成了"helloworld.exe"可執(zhí)行程序,運(yùn)行一下這個(gè)程序看到了我們期望的hello,wolrd。

E:\opensource\go\go\testgo build helloworld.go

E:\opensource\go\go\testhelloworld.exe

hello, world

E:\opensource\go\go\test

附一 helloworld.go

// cmpout

// Copyright 2009 The Go Authors. All rights reserved.

// Use of this source code is governed by a BSD-style

// license that can be found in the LICENSE file.

// Test that we can do page 1 of the C book.

package main

func main() {

print("hello, world\n")

}

Go語言編譯成aar并調(diào)試

go及gomobile的環(huán)境配置這里就不介紹了,直接說aar的生成和使用。

1. 設(shè)置環(huán)境變量GOPATH

GOPATH的值可以有多個(gè),用半角分號(hào)間隔,但不能以其結(jié)束,設(shè)置完成后需要重新做 gomobile init 。

2. 在GOPATH里創(chuàng)建src文件夾,用于存放go的包和源文件

3. 在src中創(chuàng)建hello文件夾(go文件的包名)

4. 在hello中創(chuàng)建hello.go文件,并輸入內(nèi)容

5. 編譯

執(zhí)行命令: gomobile bind -target=android hello

會(huì)生成一個(gè)hello.aar文件

6. 導(dǎo)入到android工程

將hello.aar文件放入工程的libs中,并配置build.gradle

在根結(jié)點(diǎn)加入:

在dependencies結(jié)點(diǎn)下加入依賴:

7. 在Java中測(cè)試

運(yùn)行后,結(jié)果會(huì)輸出 Hello, Android and Gopher

網(wǎng)頁名稱:go語言編譯 go語言編譯工具
分享網(wǎng)址:http://muchs.cn/article44/doedpee.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站排名網(wǎng)站改版網(wǎng)站維護(hù)、做網(wǎng)站、App開發(fā)、Google

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)