Created
June 23, 2017 22:01
-
-
Save rendicott/dd466b7f2f022f802bf1cf7880782f29 to your computer and use it in GitHub Desktop.
go build cross platform
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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