Skip to content

Is there a way to cross-compile for different CPU architectures? #224

Discussion options

You must be logged in to vote

Actually ... it turns out that this question has come up on the main Go repository on Github. There is an issue here:

golang/go#44112

This magical incantation worked just fine for me:

Arm64:

$ CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 \
    SDKROOT=$(xcrun --sdk macosx --show-sdk-path) \
    go build -o <program-name>-arm64 <path>

Amd64:

$ CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 \
    SDKROOT=$(xcrun --sdk macosx --show-sdk-path) \
    go build -o <program-name>-amd64 <path>

I was able to make a universal binary with:

$ lipo -create -output <program-name> <program-name>-amd64 <program-name>-arm64

Hope this helps!

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by corruptmemory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants