본문 바로가기
맥초보

macOS에서 golang 크로스 컴파일하기

by 촐초리 2023. 1. 25.
반응형

이전에 맥에서 윈도용 혹은 리눅스용 바이너리를 만들 수 있다

환경 설정을 하고 컴파일을 하면 간단하다

먼저 환경 변수를 설정해야 하는데 

GOOS, GOARCH 환경변수를 설정한다

값은

https://go.dev/doc/install/source

 

Installing Go from source - The Go Programming Language

Installing Go from source This topic describes how to build and run Go from source code. To install with an installer, see Download and install. Introduction Go is an open source project, distributed under a BSD-style license. This document explains how to

go.dev

에서 확인이 가능하다

맥에서 윈도용으로 컴파일을 해보자

export GOOS=windows ;export GOARCH=amd64;go build -o geoip3.exe geoip3.go

이렇게 컴파일을 하면 위와 같이 윈도용 바이너리인 exe 포맷의 바이너리 컴파일이 가능하다

위 사이트의 환경변수를 잘 보고 설정을 하면 어떤 OS 의 바이너리도 가능

 

훌륭하다 golang

반응형