1、基于ARM平台Golang简单Demo:交叉编译

2019-07-13 01:12发布

arm平台为M3352核心板。 编译环境为Ubuntu14.04 目标:在Ubuntu环境编译Go代码,在arm平台运行,每分钟打印当前时间 源代码文件名:go_arm_cross_build.go
package main import ( "fmt" "time" ) func main(){ for i:=0;i<100;i++{ fmt.Println("Hello ARM") time.Sleep(time.Second) fmt.Println(time.Now()) } } 执行编译命令: GOARM=7 GOARCH=arm GOOS=linux go build go_arm_cross_build.go  将二进制文件拷贝到M3352核心板,执行 结果如下: [root@M3352 opt]# ./go_arm_cross_build Hello ARM [root@M3352 opt]# ./go_arm_cross_build Hello ARM 2019-01-07 17:08:19.871340981 +0000 UTC Hello ARM 2019-01-07 17:08:20.87222599 +0000 UTC Hello ARM 2019-01-07 17:08:21.872714272 +0000 UTC Hello ARM 2019-01-07 17:08:22.873202554 +0000 UTC Hello ARM 2019-01-07 17:08:23.873721353 +0000 UTC Hello ARM 2019-01-07 17:08:24.874240151 +0000 UTC Hello ARM 2019-01-07 17:08:25.874697915 +0000 UTC Hello ARM 2019-01-07 17:08:26.875216713 +0000 UTC Hello ARM 2019-01-07 17:08:27.875674477 +0000 UTC Hello ARM 2019-01-07 17:08:28.876193276 +0000 UTC Hello ARM 2019-01-07 17:08:29.876681558 +0000 UTC Hello ARM 2019-01-07 17:08:30.877230875 +0000 UTC Hello ARM 2019-01-07 17:08:31.877658119 +0000 UTC Hello ARM 2019-01-07 17:08:32.878207436 +0000 UTC Hello ARM 2019-01-07 17:08:33.878726235 +0000 UTC Hello ARM 2019-01-07 17:08:34.879275551 +0000 UTC Hello ARM 2019-01-07 17:08:35.879824868 +0000 UTC Hello ARM 2019-01-07 17:08:36.880374184 +0000 UTC Hello ARM 2019-01-07 17:08:37.880831948 +0000 UTC Hello ARM 2019-01-07 17:08:38.881411782 +0000 UTC Hello ARM 2019-01-07 17:08:39.881900063 +0000 UTC Hello ARM 2019-01-07 17:08:40.882449379 +0000 UTC Hello ARM 2019-01-07 17:08:41.882907143 +0000 UTC Hello ARM 2019-01-07 17:08:42.883456459 +0000 UTC Hello ARM 2019-01-07 17:08:43.883975259 +0000 UTC Hello ARM 2019-01-07 17:08:44.884524574 +0000 UTC Hello ARM 2019-01-07 17:08:45.885043373 +0000 UTC Hello ARM ^C [root@M3352 opt]# 执行成功