h2non / bimg

Go package for fast high-level image processing powered by libvips C library
https://pkg.go.dev/github.com/h2non/bimg?tab=doc
MIT License
2.65k stars 337 forks source link

fatal error: vips/vips.h: No such file or directory #464

Open beansinc opened 8 months ago

beansinc commented 8 months ago

I tried to build a static binary using musl so it can be run in alphine:

CC=musl-gcc CGO_ENABLED=1 go build -a -ldflags '-linkmode external -extldflags "-static"' -o gowebserver main.go
# github.com/h2non/bimg
../../go/pkg/mod/github.com/h2non/bimg@v1.1.9/metadata.go:5:10: fatal error: vips/vips.h: No such file or directory
    5 | #include "vips/vips.h"
      |          ^~~~~~~~~~~~~
compilation terminated.

I also attempted with gcc:

CC=gcc CGO_ENABLED=1 go build -a -ldflags '-linkmode external -extldflags "-static"' -o gowebserver main.go
# command-line-arguments
/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: cannot find -lvips: No such file or directory
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/libglib-2.0.a(gutils.c.o): in function `g_get_user_database_entry':
(.text+0x29f): warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: (.text+0xe0): warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: (.text+0x11e): warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-4234432590/000004.o: in function `_cgo_9c8efe9babca_C2func_getaddrinfo':
/tmp/go-build/cgo_unix_cgo.cgo2.c:58:(.text+0x37): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
collect2: error: ld returned 1 exit status

Building a normal binary works fine, but it doesn't suit my usecase: go build -o gowebserver main.go My final goal is to run this go binary inside a docker alpine container.

Vips Location

whereis vips
vips: /usr/bin/vips /usr/lib/vips /usr/include/vips /usr/share/man/man1/vips.1.gz
ls /usr/include/vips/
almostdeprecated.h  conversion.h   dispatch.h   freqfilt.h   interpolate.h  object.h     sbuf.h        util.h          VImage8.h
arithmetic.h        convolution.h  draw.h       gate.h       intl.h         operation.h  semaphore.h   VConnection8.h  VInterpolate8.h
basic.h             create.h       enumtypes.h  generate.h   mask.h         private.h    thread.h      vector.h        vips7compat.h
buf.h               dbuf.h         error.h      header.h     memory.h       rect.h       threadpool.h  VError8.h       vips8
colour.h            debug.h        foreign.h    histogram.h  morphology.h   region.h     transform.h   version.h       vips.h
connection.h        deprecated.h   format.h     image.h      mosaicing.h    resample.h   type.h        video.h         VRegion8.h

Version

vips -v
vips-8.14.3

OS Ubuntu 23.10 x86_64 6.5.0-14-generic

Go Version

go version
go version go1.21.4 linux/amd64

musl Version

musl-gcc --version
x86_64-linux-gnu-gcc (Ubuntu 13.2.0-4ubuntu3) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

gcc Version

gcc --version
gcc (Ubuntu 13.2.0-4ubuntu3) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.