Skip to content

Instantly share code, notes, and snippets.

@rendicott
Created June 23, 2017 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rendicott/dd466b7f2f022f802bf1cf7880782f29 to your computer and use it in GitHub Desktop.
Save rendicott/dd466b7f2f022f802bf1cf7880782f29 to your computer and use it in GitHub Desktop.
go build cross platform
#!/bin/bash
#Binary built in alpine docker causes OOM exceptions in runtime on c3.xl centos7 (self.golang)
#submitted 9 hours ago
#If I build on the c3.xl it's fine. Everything I'm reading about cross compilation involves building from nix to Windows/ Darwin but not much about platform. I'm woefully ignorant here.
#Anyone have tips for reading resources?
#2 commentsshare
#all 2 comments
#sorted by: best
#[–]kron4eg 3 points 4 hours ago
#alpine uses alternative libc implementation (musl), and looks like you've used cgo - resulted binary links to libc. Centos uses glibc. Ether disable cgo, or build on target glibc
#permalinkembed
#[–]hayzeus 1 point an hour ago
#I believe that go by default will still iink the system libc dynamically. But alpine uses musl -- so the way I've dealt with this in the past is to statically link libc when cross-compiling for alpine.
#GOOS=linux GOARCH=amd64 go build --ldflags '-extldflags "-static"' foo.go
#EDIT: When cross-compiling.
#Should run on either.
#verflag=$1
go test ./... -v
go build -o ./build/binary.exe -ldflags '-X main.version=$verflag -extldflags "-static"'
ls -al ./build/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment