Go cross compilation for beginners

Cross compilation under windows

Table of contents

 Tool 1: Use powershell tool to compile

Tool 2: goland tool compilation


 Tool 1: Use powershell tool to compile

##### Linux

$env:GOOS="linux"

$env:GOARCH="amd64"

Normal build go build

Compressed build go build -ldflags="-s -w"

For other cross-copied content, see below

Tool 2: goland tool compilation

Linux compilation as an example

SET CGO_ENABLED=0 # Whether to use C language compilation

SET GOOS=linux

SET GOARCH=amd64

go build -ldflags="-s -w"

Additional compilation settings for powershell

##### Linux(arm) Raspberry Pi

$env:GOOS="linux"

$env:GOARCH="arm"

Normal build go build

Compressed build go build -ldflags="-s -w"

##### Windows

$env:GOOS="windows"

$env:GOARCH="amd64"

Normal build go build

Compressed build go build -ldflags="-s -w"

##### Linux  mipsle

$env:GOOS="linux"

$env:GOARCH="mipsle" 

$env:GOMIPS="softfloat"

Normal build go build

Compressed build go build -ldflags="-s -w"

##### Mac

$env:GOOS="darwin"

$env:GOARCH="amd64"

Normal build go build

Compressed build go build -ldflags="-s -w"

How to open powershell:

1. Shortcut key win+X

  2. In the project directory, hold down shift, right-click, and select

3. Run the command to open cmd and enter powershell

There are more methods. To explore by yourself, you   can refer to this article : How to use powershell in win10_Dadaguyue's blog-CSDN blog_win10powershell

Guess you like

Origin blog.csdn.net/xia_2017/article/details/125664586