How do you statically link a c library in go using cgo?

Turns out my code is 100% fine; it was a copy of Go 1.0; under go 1.1 this works.
Under go 1.0, it doesn’t.

(it’s a bit lame answering my own question, I know; but the ‘use -L -l answers below aren’t right either; it had nothing to do with that).

A working solution example is up on github here for anyone who find’s this question later:

https://github.com/shadowmint/go-static-linking

in short that looks like:

CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags '-s' src/myapp/myapp.go

see also:
https://github.com/golang/go/issues/9344

Leave a Comment