-
-
Notifications
You must be signed in to change notification settings - Fork 0
Cross‐compiling for Linux from macOS ARM64
Ben Lavery-Griffiths edited this page Aug 14, 2023
·
1 revision
I do some development on an M1 MacBook, and since adding SQLite support we also needed to start building with CGO_ENABLED=1
which causes some issues when cross-compiling to Linux.
A work around in to install musl-cross
:
brew install FiloSottile/musl-cross/musl-cross
And then compile with:
CC=x86_64-linux-musl-gcc CXX=x86_64-linux-musl-g++ GOARCH=amd64 GOOS=linux CGO_ENABLED=1 go build -ldflags "-linkmode external -extldflags -static"
This will allow you to build the binary for Linux amd64 on your Mac with an M1 o rM2 processor.