Golang 交叉编译跨平台的可执行程序 (Mac、Linux、Windows )

起因: 在项目中,我们每一次提交都需要添加commit 信息,而且我们的commit 信息,比较繁琐.我决定用golang语言编写一个小工具.

我决定使用语言:golang,使用工具:gox包. gox github  https://github.com/mitchellh/gox

创建一个文件,写入以下golang代码,过于简单不做解释.

package main

import (
	"time"
	"fmt"
	"io/ioutil"
	"os/exec"
)

func main() {
	b, err := ioutil.ReadFile("git-message.txt")
	if err != nil {
		fmt.Print(err)
	}
	str := string(b)

	fmt.Println(str)
	command := exec.Command("git", "commit -m", str)

	if err := command.Run(); err != nil {
		fmt.Print("执行失败")
		time.Sleep(time.Duration(3)*time.Second)
	}else{
		fmt.Print("执行成功")
	}
}

 安装:   go get github.com/mitchellh/gox

 查看"该工具支持的命令": gox -h

 查看当前你的GO版本可编译成的系统类型(List supported os/arch pairs for your Go version):  gox -osarch-list

 项目文件夹中执行如下命令:

  1.打包window 64位    gox -osarch="windows/amd64" ./

  2.打包mac 64位 gox -osarch = "darwin/amd64" ./

  3.打包Linux 64位 gox -osarch="linux/amd64" ./

文章结束.如有疑问请留言. 

扫描二维码关注公众号,回复: 6147941 查看本文章

猜你喜欢

转载自www.cnblogs.com/jingying/p/10815504.html