Notice
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- golang
- 맥미니
- vscode
- Linux
- opentelemetry
- log
- pg_stat_statements
- 무선 디버깅
- rc-service
- SQL Server
- module upgrade
- AnimatedPositioned
- User
- Flutter
- sqlc
- DotNet
- elasticSearch
- shared_preload_libraries
- option pattern
- user-secrets
- 윈도우즈 터미널
- mysql
- go
- otel
- version 2
- openrc
- 옵션 패턴
- IDX Project
- Android
- docker
Archives
- Today
- Total
CATCHV Blog
Golang cross-compile windows, mac(darwin), linux 본문
반응형
go에서 빌드를 하는 경우 바이너리 실행파일을 생성합니다.
그런데 바이너리 실행파일은 OS(windows, mac, linux)별 아키텍쳐(x86, x64, arm64)별로 다른 구조 및 라이브러리 참조가 다르기 때문에 빌드시에 어떤 타켓으로 빌드 할 지 결정이 필요합니다.
go build 시에는 go env에 저장된 환경변수 파일에 따른 정보로 빌드가 됩니다.
GOARCH='arm64' GOHOSTARCH='arm64' GOHOSTOS='darwin' GOOS='darwin' |
1. Windows 바이너리 컴파일
# Windows x64 빌드
GOOS=windows GOARCH=amd64 go build
# Windows x86 빌드
GOOS=windows GOARCH=386 go build
2. Mac 바이너리 컴파일
# Mac x64 빌드
GOOS=darwin GOARCH=amd64 go build
# Mac x86 빌드
GOOS=darwin GOARCH=386 go build
# Mac arm64 빌드(M1, M2 등)
GOOS=darwin GOARCH=arm64 go build
3. linux 바이너리 컴파일
# Windows x64 빌드
GOOS=linux GOARCH=amd64 go build
# Windows x86 빌드
GOOS=linux GOARCH=386 go build
# Windows x86 빌드
GOOS=linux GOARCH=arm64 go build
Golang에서 지원되는 크로스 컴파일 리스트는 Go Doc을 참고 하면 됩니다.
https://go.dev/doc/install/source#environment
반응형
'Dev > Go' 카테고리의 다른 글
go 1.22 for loop 변경 (0) | 2024.02.23 |
---|---|
dotnet으로 Golang gin 로컬 개발(localhost) 인증서 만들기 (0) | 2024.01.11 |
go - package (1) | 2023.11.24 |
go module upgrade (0) | 2023.11.13 |
golang fiber + otel + recover middleware 호출 순서 (0) | 2023.11.10 |
Comments