I'm running goreleaser build -f goreleaser_build.yml
, on REHL linux. When setting no flag, the binary it builds has a few shared dynamic linked libraries:
linux-vdso.so.1 => (0x00007fff239f6000)
libm.so.6 => /lib64/libm.so.6 (0x00007f3a38370000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f3a3816c000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f3a37f50000)
librt.so.1 => /lib64/librt.so.1 (0x00007f3a37d48000)
libc.so.6 => /lib64/libc.so.6 (0x00007f3a3797a000)
/lib64/ld-linux-x86-64.so.2 (0x00007f3a38672000)
My goal is to link all them but libc statically. When running go build
i assume it's like go build -lpthread -lm
etc, but goreleaser
does not accept such flags. There's a ldflags
setting in goreleaser file, but I can't seem to set it to take effect.
My goreleaser file is almost like default:
builds:
- binary: <name>
main: cmd/<name>/main.go
flags:
- -mod=readonly
- -tags={{.Env.TAGS}}
ldflags:
- -s -w -X main.version={{.Env.VERSION}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}} -X main.host={{.Env.HOSTNAME}}
gcflags:
- all=-trimpath={{.Env.HOME}}/git
asmflags:
- all=-trimpath={{.Env.HOME}}/git
Also tried setting export CGO_LDFLAGS="-g -O2 -lm"
but it has no effect. libm is still dynamic.
How can I set it via goreleaser file flags / go env vars, to make it link to those libraries statically? (i can't -static
because I still need libc dynamic). Thank you!