【golang】之build

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/langhailove_2008/article/details/86706319

mac环境下build 的go二进制文件只能在mac本执行。
在linux环境跑二进制文件会报错。
所以如果想让mac上build的二进制文件可以在linux系统运行,需要按照如下方式build:

mmmm@localhost  /xxxxxxx/study/github/gopl.io/ch1/dup2   master ●   GOOS=linux GOARCH=amd64 go build main.go 
mmmm@localhost  /xxxxxxx/study/github/gopl.io/ch1/dup2   master ●  ll
total 7832
-rwxr-xr-x  1 xxxxxx  staff   1.9M Jan 30 16:30 golang_check_dup_for_file
-rwxr-xr-x  1 xxxxxx  staff   1.9M Jan 30 16:35 main
-rw-r--r--  1 xxxxxx  staff   974B Jan 30 16:29 main.go

这样生成的二进制文件main scp到linux机器就可以运行了!
当然为了使用的方便可以mv改名如上golang_check_dup_for_file 等价于main文件。

猜你喜欢

转载自blog.csdn.net/langhailove_2008/article/details/86706319
今日推荐