Skip to content

Instantly share code, notes, and snippets.

@myl7
Created January 25, 2022 05:09
Show Gist options
  • Save myl7/1f43c46e8cd10494524b8bcc317b670e to your computer and use it in GitHub Desktop.
Save myl7/1f43c46e8cd10494524b8bcc317b670e to your computer and use it in GitHub Desktop.
Staticly build go even with cgo but excluding external dynamic libraries
#!/usr/bin/env bash
set -euo pipefail
# Ref: https://honnef.co/posts/2015/06/statically_compiled_go_programs__always__even_with_cgo__using_musl/
CC=musl-gcc go build --ldflags '-linkmode external -extldflags "-static"' "$@" cmd/bibak/main.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment