LoginSignup
0
0

More than 5 years have passed since last update.

Go言語のクロスコンパイルを試してみる

Posted at

クロスコンパイルが簡単と噂のgoさん。せっかくなので、クロスコンパイルをしてみようと思います。
ビルド CentOS7
実行 macOS High Sierra(10.13.6)

CentOSでGoをビルドする

「ハローワールド」するだけのコードです。ファイル名はhello.goです。

package main

import "fmt"

func main() {
  fmt.Println("hello go world from centOS")
}

そのままビルド時に、Macを指定

$ GOOS=darwin GOARCH=amd64 go build hello.go 

対応表は、公式を御覧ください。https://golang.org/doc/install/source#environment

Macで動くか確認

ダウンロードしたディレクトリに移動し

$ ./hello

実行結果

hello go world from centOS

動いた!
簡単だ!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0