Skip to content

Instantly share code, notes, and snippets.



Created Jun 23, 2017
What would you like to do?
go build cross platform
#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
#[–]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.
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