How to staticly compile?
berney opened this issue · comments
I've tried go build -ldflags '-extldflags "-fno-PIC -static"' -buildmode pie -tags 'osusergo netgo static_build'
and go build -ldflags '-extldflags "-fPIC -static"' -buildmode pie -tags 'osusergo netgo static_build'
.
Both get issues with trying to link.
/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/libpthread.a(pthread_create.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/libpthread.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
I don't want a shared object I want a self-contained static binary that I can use in a Docker container FROM scratch
.