Hi all, I’m trying to create a static binary (no external deps) for linux, on linux, using libwebp as dep.
webp.go
=======
...
/*
#cgo pkg-config: libwebp
#include <webp/encode.h>
#include <stdlib.h>
...
*/
import "C"
...
=======
And I wand to generate a static linked bin.
If I use CGO_ENABLED=0
=======
... build constraints exclude all Go files in ...
=======
If I use
=======
go build -o bin/api \
-ldflags -extldflags=-static \
...
=======
A giant error comes:
=======
...
/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: /tmp/go-link-
3823308014/000004.o: in function `_cgo_cbcce81e6342_C2func_getaddrinfo':
/tmp/go-build/cgo-gcc-prolog:58: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
...
=======
If I just run go build, it compiles and run perfectly but
=======
$ ldd bin/api | wc -l
7
=======
I’m not sure if is it even possible, but is there something that can be done?